I've often having to hack in UNIX / Linux servers with Apache VirtualHost management compromised by years of uncontrolled use of servers by system administrators do not really sorted. The result is usually a large number of users with home directory structured differently from one another.

In particular, in a recent case I found myself a hundred members of which had a certain part of the DocumentRoot in your home directory, while others had no under / var / www / users /, which I recommend because it avoids have problems with suEXEC precompiled versions of Apache.

To place a chaotic situation so I decided to put everything right in / var / www / users / and I was presented with the need to automatically create the missing directory and its symbolic links to the various home directory. I did that with a simple bash script, that the public here in case it might be useful to someone else. It took me a little 'output to make the code clear to those who are the first weapons in bash.

Warning! Line 18 is a copy of a fast-cgi in the directory / var / www / users / ivan /. Obviously you have to replace Ivan as a user present on your server.

 
 # / Bin / bash


 echo "Initializing Scripts ..."


 for i in $ (ls / home /) do
  
 echo "I'm processing '$ i'"
  
 if [-L / home / $ i / public_html], then
    
 echo "symlink / home / $ i / public_html already exists' ... jump!"
  
 else
    
 echo "symlink / home / $ i / public_html does not exist: I try to create it ..."
    
 if [-d / var / www / users / $ i]; then
      
 echo "The directory / var / www / users / $ i exists, I just have to link it ..."
      
 / Bin / ln-s / var / www / users / $ i / home / $ i / public_html
    
 else
      
 echo "The directory / var / www / users / $ NON there, now I create ..."
      
 / Bin / mkdir / var / www / users / $ i
      
 echo "Copying the FAST-CGI ..."
      
 / Bin / cp / var / www / users / ivan / fast-cgi / var / www / users / $ i /
      
 echo "He set the permissions for the directory created ..."
      
 / Bin / chown-R $ i: $ i / var / www / users / $ i
      
 / Bin / chmod 700 / var / www / users / $ i
      
 echo "I create the symbolic link ..."
      
 / Bin / ln-s / var / www / users / $ i / home / $ i / public_html
    
 fi
  
 fi

 done