Script to rebuild /var/spool/virtual

chatwizrd

Verified User
Joined
Jul 3, 2005
Messages
2,005
Hi.

I dont know if anyone has ever done this but the other day I noticed I had lost all the directories in /var/spool/virtual. Well I have written a script to rebuild those and set to the proper owners.

Enjoy!

Should work fine on Linux and Freebsd.

----

How to use:
Code:
Put the following script into a txt file in /var/spool/virtual

I named mine /var/spool/virtual/rebuild

Then type:

chmod 750 /var/spool/virtual/rebuild

Then type:

cd /var/spool/virtual
./rebuild

Script:
Code:
#!/bin/sh

pwd=$(pwd) # Keep set to pwd or set to full path to the pwd command.
whoami=$(whoami) # Keep set to whoami or set to full path of whoami command.


################### DO NOT TOUCH CODE UNDER HERE #####################


domainowners=$(cat /etc/virtual/domainowners | sed 's/://' | tr -s ' ' ':')

if [ $whoami != "root" ]; then
        echo
        echo "You must be root to run this program!"
        echo
        exit 1

elif [ $pwd != "/var/spool/virtual" ]; then
        echo
        echo "You must be in the /var/spool/virtual folder to run this program."
        echo
        exit 1
else

for i in $domainowners; do

        # Create Domain Folder
        echo $i | cut -f1 -d: > /tmp/domains.$$
        mkdir $(cat /tmp/domains.$$)

        # Chown Domain Folder
        echo $i | cut -f2 -d: > /tmp/users.$$
        chown $(cat /tmp/users.$$):$(cat /tmp/users.$$) $(cat /tmp/domains.$$)
done

fi

rm -rf /tmp/domains.$$ /tmp/users.$$
exit 0
 
I've moved this post to How-To Guides.

I haven't tested it but it should fill an important need.

Jeff
 
Well their script is way over bloated for one. Secondly I didnt even know it existed.

I think its alot easier just reading the /etc/virtual/domainowners file to gather the info assuming it didnt get messed up.

For adding the domains to your rbl_domains file I dont know what that is but u can do this:

Code:
cat /etc/virtual/domainowners | sed 's/://' | awk '{print $1}' > /etc/virtual/use_rbl_domains

All my script was designed to do was rebuild the /var/spool/virtual/domain.com files nothing else. It does nothing in /etc/virtual or anywhere else.
 
chatwizrd,

While you were busy responding to my post, I was busy rewrting it.

I misread your post.

Please see my new reply, which is above your reply :) .

Jeff
 
Back
Top