I'm using Macosx 10.6 and doing web design onto it. I understand a little amount about writing spend scripts, but I'm not really experienced inside them by yet.

What I must do would be to write a spend script which will simply request for any local site alias and also the document directory and it'll then append the brand new alias onto hosts with something similar to "127...1 mysite.local" on the new line at the end of etc/hosts.

Then your script would append Apache's httpd-vhosts.conf file with something similar to this:

<VirtualHost *:80>
    DocumentRoot "/Repositories/myproject/mysite.com/trunk/htdocs"
    ServerName mysite.local
    ServerAlias mysite.localhost
</VirtualHost>

It would finally run the command to restart my Apache server. Now we all know the terminal command to restart Apache, that's not so difficult. I additionally understand how to read within the site title and path in the user running the script. For example below:

#!/bin/bash
read -p "New local site name: " site
read -p "Site path (ex:/Repositories/myproject/mysite.com/trunk/htdocs): " sitepath

What I'm not sure how you can do would be to append text to some file from terminal.

Any ideas or useful ideas?

Thanks, Patrick

Untested, however it should work:

#!/bin/bash
read -p "New local site name: " SITE
read -p "Site path (ex:/Repositories/myproject/mysite.com/trunk/htdocs): " SITEPATH

#/etc/hosts
cp /etc/hosts /etc/hosts.original
echo -e "127.0.0.1\t${SITE}.local" >> /etc/hosts

#httpd-vhosts.conf
VHOSTSFILE="/etc/apache2/httpd-vhosts.conf"
cp $VHOSTSFILE ${VHOSTSFILE}.original
echo "<VirtualHost *:80>" >> $VHOSTSFILE
echo -e "\tDocumentRoot \"${SITEPATH}\"" >> $VHOSTSFILE
echo -e "\tServerName ${SITE}.local" >> $VHOSTSFILE
echo -e "\tServerAlias ${SITE}.localhost" >> $VHOSTSFILE
echo '</VirtualHost>' >> $VHOSTSFILE

#restart apache

>> redirects the output towards the given file, appending the contents towards the file. I’m also using -e to permit \t to become broadened to some tab character.

Note you need to run this script with sudo. I have also incorporated instructions to backup the initial files before modifying them, just just in case.