Update Website Permissions Script

Here I have a script that answers a question posted on the opensuse.org.suse-linux.support forums.

1. The script first removes the ~ backup files from the source directories.
2. It then copies the files to the web server using scp.
3. Using the ssh command it then changes the permissions on the the directories.
Note the -depth option is important. It means the directories at the bottom of the structure are changed before directories further up. This avoids an issue where permissions might be changed that stop you from changing into a lower directory.
4. The ssh command is used again to change the permissions of the files.

As this script stands you will be prompted to login each time the ssh or scp commands are executed. To avoid this you will need to setup the Public/Private key system. This is beyond the scope of this script, but a helpful tip on setting up public key distribution is in my Tips n Tricks section.

This script is very basic and works for me. I have no control over it working for you so use at your own risk.

And Kevin thanks for the tip on chkstat ;-)

Cheers Jim

 

#!/bin/bash
# (c) Jim Pye 20060206

#Remove backup ~ files
find /local/develop/dir/www-site/ -depth -type f -name '*~' -exec /bin/rm {} \;

echo "Copying the files to site"
scp -C -r /local/develop/dir/www-site/* user@webserver:/srv/www/htdocs/

echo "Changing Directory permissions"
ssh -C user@webserver "/usr/bin/find /srv/www/htdocs/ -depth -type d -name '*' -exec /bin/chmod -c 0705 {} \;"

echo "Changing File Permissions"
ssh -C user@webserver "/usr/bin/find /srv/www/htdocs/ -depth -type f -name '*' -exec /bin/chmod -c 0604 {} \;"