I'm a newbie server administrator having recently purchased an account from Slicehost.com and using it to host a few personal sites, so I can learn more (I'm primarily a web developer).
Years ago I remember playing with batch scripts on Windows that would allow me to automate certain basic things. Does anything like this exist for Unix?
I would like to automate setting up of new domains in Apache2, so basically creating directories, setting permissions, creating the configuration file in sites-available then running the a2ensite command and finally restarting Apache.
Is this achievable from a basic script I can run from the command line? Any basic pointers and guidance you can give would be much appreciated.
Thanks!
I'd suggest you read up on bash scripting.
Some good links:
Bash is a lot more powerful than a batch file :)
It is definitely doable. Anything that can be accomplished by a series of commands on the command line can be put into a bash script and run from there.
The script starts with #!/bin/bash or #!/bin/sh (for sh instead of bash) After that # starts a comment line $VARIABLE_NAME can be used to refer to a variable set by VARIABLE_NAME=foo
Command line parameters can be grabbed starting with $1, ($0 is the name of the program that was called).
so if you want to evoke a script as script.sh new_site
you could have script.sh looks something like this
#!/bin/sh
mkdir /var/www/htdocs/new_site chmod 755 /var/www/htdocs/new_site ... apachectl restart
then you simply have to run the script with sufficient permissions actually perform all the commands run.
Use sh -x to debug (it will step through the script with lots of output so you can tell what is actually happening).
You might also look into puppet. It's a bit of overkill for a single server, but is definitely designed to handle this kind of thing.