Scripting.


A script can be compared to a batch file that is used to carry out multiple tasks in one process. Without the use of scripts it would be extremely difficult to keep the server online & monitor the services. The ability to write a script a very useful & anyone who has any programming experience will have no problem. That being said there are many very simple things that can be used in a script. Here's an example of a script I wrote to connect the server, via an ADSL modem, to the net, & to start the firewall & reboot apache.

# line-up written by unclebob
# connect to net & start firewall, return ip address.
PATH=/sbin:/sbin/init.d:/bin:/usr/bin:/usr/sbin:/usr/local/bin

rcpppoed start

sleep 5s

echo starting firewall....
. /usr/firewall/firewall start

echo your new ip address is....
echo `ifconfig ppp0 | grep inet | cut -d: -f2 | cut -d " " -f1`

echo logging in to www.hn.org for www.highasakite.net....
perl /usr/auto.scripts/hn.pl

sleep 300s

echo rebooting apache....
/sbin/init.d/apache restart

echo end of reconnection process!

The # symbol at the beginning of a line is the same as the rem command under DOS. You carry out 4 tasks in one easy operation & that can be fully automated, but more to that in the "detailed web server" section. This one script starts several other scripts. This script carries out these tasks without any interaction with the system & can be used by another "type" of script which carries out check routines on the running system. Have a look at an example of a script used to check if the server is on line.

# line-check written by unclebob
# check connection to net.
# is started by a crontab job.

PATH=/sbin:/bin:/usr/bin:/usr/sbin

if [ -z `/sbin/ifconfig ppp0 | grep inet | cut -d: -f2 | cut -d " " -f1` ] ; then
     echo line disconnected!!
     date
     echo reconnecting....
     . /usr/auto.scripts/line-up

fi

With just these two small pieces of "text" we have a fully automated way of connecting (& maintaining) the server to the internet & starting the important services for the web server. At the beginning of my web server project I had lots of fun trying to find a way to keep my connection to the net, & even more fun trying to get my head around the whole thing :o). Keep in mind that I'd never used Linux before, & 4 weeks later the server was running fully automated & serving 3 web sites, collecting & sending emails, .....

Scripting is a very easy way to carry out many tasks, without having to have to find loads of software to do the special tasks you require, if you could find it at all! At the end of the day you know better than anyone else what you require, but a bit of time spent thinking of the different ways of carry out the task will help in finding the best way of actually doing it. There is a load of really good information on the web, plus loads of script sites where you may find exactly what you are looking for. If not then you may just find the answer you were after. Take a look at the scripts & crontab section for more detailed information about the scripts you will need for the web server. Have a look at the links page for more information.




back a page    back to main index    forward a page

copyright 2001 Rob Hawke.
rob@highasakite.net