If you run any type of Web hosting service like me, you know what a pain in the ass it can be to have to add new virtual hosts to your Web server. If you have Linux and Apache, here's a quick'n'dirty little script that will save you a ton of time:

if [ -t 0 ] # Make sure stdio is a terminal


echo "Enter the new hostname:";

read arg1

/usr/sbin/useradd -s /bin/false $arg1;

echo "User added...";

sed -e "s/name.com/$arg1/g" virthost.conf >> httpd.conf;

/usr/local/apache/bin/apachectl restart;

echo "$arg1 was added and Apache restarted. You're so sexy!";

chmod 755 /home/$arg1;


echo "Houston, we had a problem!"


Step by step:

Now, this script is extremelly lacking in the error and exception checking department, so use at your own risk. Like I said, its quick'n'dirty :) However, if you are adding a couple virtual host's a day to your httpd.conf file, you'll soon be wonder where you would be without a script to do the grunt work for you..

Next time we'll throw together a script that will make updating your DNS servers a snap. If you have any other ideas for shell scripts that would make your life easier, and like to see them here, email me or put your suggestion below!