Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 2 > Tips/Tricks/Mods

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 30th May 2009, 23:11
shrek shrek is offline
Junior Member
 
Join Date: Apr 2009
Posts: 18
Thanks: 0
Thanked 4 Times in 1 Post
Default Restoring permissions of /var/www after wrong chmod

Hello, today I have written a simple script to make back default chmods of whole /var/www, I wrote it because of chmod -R done in wrong directory. May be somebody will enjoy it and will find it helpful

It is done for [domain] indentifiers. And modyfies all files to "standard" if you have your own directories you will have to modify script.

You're using script on your own responsibility!!
It works well for me.
Any suggestions or misteakes I'll be updating it on my blog page

Code:
#! /bin/bash
#Shrek ISPConfig2 Permissions script
#Variables
root=root:root
www=www-data
no=.no_delete
dir=/var/www
 
#Gets web[0-9]* directories into table
ls -alh $dir | grep drwx | grep -e "[0-9][0-9]:[0-9][0-9] web[0-9]" | awk '{print $9}' > .web_dirs
n=1
exec < .web_dirs
while read line
do
        web_dirs_list[$n]=$line
        n=$n+1
done
 
#echo ${#web_dirs_list[@]}
no_of_dirs=${#web_dirs_list[@]}
 
for ((k=1;k<=no_of_dirs;k++))
do
        web=${web_dirs_list[$k]}
        echo "Restoring Permissions of $dir"
        echo $web
        #Owning a web[0-9] directory to www-data:web[0-9]
        chown www-data:$web /var/www/$web -R
        #Owning root permission files
        chown $root $dir/$web/cgi-bin/$NO
        chown $root $dir/$web/log/error.log
        chown $root $dir/$web/log/$NO
        chown $root $dir/$web/phptmp/$NO
        chown $root $dir/$web/ssl/$NO
        chown $root $dir/$web/user/$NO
        #Owning User files
        #Getting user namse/dirs
        ls -alh $dir/$web/user/ | grep drwx | awk '{print $9}' | grep -e ".[a-z]_[a-z]" > .users
        m=1
        exec < .users
        while read line
        do
                user_list[$m]=$line
                m=$m+1
        done
 
        #echo ${user_list[@]}
        no_of_users=${#user_list[@]}
        echo $no_of_users
        zero=0
        if(($no_of_users>=$zero ))
        then
                #Owning files to their owners
                for((x=1;x<=$no_of_users;x++))
                do
                        user=${user_list[$x]}
                        echo "$web/user/$user"
                        chown $user:$web $dir/$web/user/$user -R
                        chown $root $dir/$web/user/$user/.antivirus.rc
                        chown $root $dir/$web/user/$user/.autoresponder.rc
                        chown $root $dir/$web/user/$user/.html-trap.rc
                        chown $root $dir/$web/user/$user/.local-rules.rc
                        chown $root $dir/$web/user/$user/.mailsize.rc
                        #Some users does not have .procmailrc file
                        chown $root $dir/$web/user/$user/.procmailrc
                        chown $root $dir/$web/user/$user/.quota.rc
                        chown $root $dir/$web/user/$user/.spamassassin.rc
                        chown $root $dir/$web/user/$user/.user_prefs
                        chown $root $dir/$web/user/$user/.vacation.msg
                done
                no_of_users=0
                unset user_list[*]
        fi
        #Owning symlinks
        symlink=`ls -alh /var/www | grep $web | grep lrwx | awk '{print $9}'`
        echo $symlink
        chown $www:$web $dir/$symlink
rm -f .users
rm -f .web_dirs
done
Reply With Quote
The Following 4 Users Say Thank You to shrek For This Useful Post:
falko (31st May 2009), madmucho (31st May 2009), mccharlet (1st June 2009), till (31st May 2009)
Sponsored Links
  #2  
Old 1st June 2009, 14:49
mccharlet mccharlet is offline
Senior Member
 
Join Date: Feb 2007
Posts: 261
Thanks: 63
Thanked 11 Times in 7 Posts
Default

Hi,

If the backup was a tar (and not a zip) file the permissions is backuped.
__________________
Thanks
Cédric

Sorry for my english

Hosting : http://www.jheberge.ch
Reply With Quote
  #3  
Old 1st June 2009, 21:15
shrek shrek is offline
Junior Member
 
Join Date: Apr 2009
Posts: 18
Thanks: 0
Thanked 4 Times in 1 Post
 
Default

hi,
If there is no backup then no permissions are backuped ;]
Or if we want to restore permissions in a very quick way, script will help a little with it.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP!!! Wrong permissions blocker General 14 1st July 2008 23:02
File Permissions demonize Installation/Configuration 0 26th June 2008 20:11
Installation Troubles bswinnerton Installation/Configuration 4 29th July 2007 16:56
Wrong chmod!! nox171 General 9 19th February 2007 11:18
Joomla & MySql config and chmod permissions normdouglas Installation/Configuration 6 27th December 2006 12:39


All times are GMT +2. The time now is 22:48.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.