crontabs are wonderfull and easy, check it out
Quote:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
#setiman script
00 04 * * * root /seti/server/setiman
There is my /etc/crontab file, take the setiman script for example this says:
MINUTE(0-59) HOUR(0-23) DAYOFMONTH(1-31) MONTHOFYEAR(1-12) DAYOFWEEK(0-6) Note 0 = Sun
so in other words, on the 0th minute if the 4th hour on (classic expansion here) ANY day, ANY month ANY day of the week run the script /seti/server/setiman
Now if you usr redhat they made some easy thing for people to, you have
/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly
and if you put a script in those folders it will be run respectively at the time, every day, etc... You will also need to put your script in a file, and make sure it has executable permission
Quote:
#!/bin/bash
#this means loop forever
while [ 1 ];
do HTTP=`ps auwxf | grep httpd | grep -v grep | wc -l`;
#the above line counts the number of httpd processes found running
#and the following line says if there were less then 10 found running
if [ $[HTTP] -lt 10 ];
then killall -9 httpd;
#inside the if now, so there are less then 10, kill them all and wait 1 second
sleep 1;
#start apache
/var/lib/autoadmin/apache/bin/httpd;
fi;
#all done, sleep for ten seconds before we loop again
sleep 10;done
save that to some file, and chmod 700 it (you may want root to own it that way noone else can modify it and have your http server shutdown)
Now if you add THAT file to a crontab you will have the first time it is called looping forever, and then teh next call will loop forever .. etc etc so if you want to make it a crontab just do this
Quote:
#!/bin/bash
HTTP=`ps auwxf | grep httpd | grep -v grep | wc -l`;
#the above line counts the number of httpd processes found running
#and the following line says if there were less then 10 found running
if [ $[HTTP] -lt 10 ]; then
killall -9 httpd;
#inside the if now, so there are less then 10, kill them all and wait 1 second
sleep 1;
#start apache
/var/lib/autoadmin/apache/bin/httpd;
fi;
exit 0
Nw you could do this alot of other ways, many of which are cleaner - but congrats on getting the script going in the first place.