On Thursday 17 April 2008 03:49, Deepan wrote: > Hi All, > I am looking for a script to check if Apache is up > and running, if not the script should send an > email automatically. Although my preference is to have a cron running on the server itself: SIM - System Integrity monitor a shell script/cronjob that installs and configures painlessly http://www.rfxnetworks.com/sim.php
Alternately, below will check to see if it's running, and if it's not, start it
and send
you the date/time it was started and the last 10 lines of the error log.
If you run it in cron, you'll get email with the output, otherwise execute it
via ssh
ssh -c blowfish -p 22 [EMAIL PROTECTED] /path/to/checkHttpd.sh
cat /root/Scripts/checkHttpd.sh
#!/bin/sh
APACHE=/usr/local/sbin/apachectl
PID=`ps -auxw | grep httpd | grep "\-DSSL" | grep root | awk {'print $2'}`
DATE=`date +"%m-%d-%H:%M:%S"
LOG=`tail /var/log/httpd-error.log`
if [ ! -z $PID ]; then
$APACHE start
#echo 'ALERT - restarted Apache2 on:' `date` | mail -s "Alert: Apache
Restart on `hostname` " [EMAIL PROTECTED]
echo "Restarted apache at $DATE"
echo $LOG
fi
Since many perl scripts require various modules, they may need a trip to CPAN
to get running.
From a remote host the simplist path i use is to install httping (included) and
run as a cronjob.
Another method would be to install snmp (yum install net-snmp)
on the remote machine and use nagios, or cacti,
or even Zenoss (Open Source Enterprise Monitoring) - http://zenoss.com/download
Hope this helps,
Rion
> The script has to be run from
> a different machine (not from the machine that
> runs apache). So it has to query for a http
> address and if it receives any other reply that
> 200 OK, it should send the email.
> Can you guys
> suggest on how to go about ?
http://www.linux-sec.net/Monitoring/
> Should I use curl ?
> or wget ? or ping ? I can handle the email part
> and cron part. If you guys have a similar script
> please share it if possible.
> Regards
> Deepan
> Sudoku Solver: http://www.sudoku-solver.net/
>
--
email: rion_at_dluz.com
web: http://dluz.com/Rion/
AIM: riondluz
Phone: 802.644.2255
http://www.linkedin.com/pub/6/126/769
the #1 rule of Usenet is: YOU DO NOT TALK ABOUT USENET.
{ } . ! /
& ; ^ # -
< > @ \
{ } _ SYSTEM HALTED
"Left titty, right titty, dot bang slash.
Ampersand semicolon, caret pound dash.
Less than greater than, at back slash,
left titty, right titty, under score crash!"
* # ! ! (
~ & | )
' " . . DEL
# ^G ! ! working... done.
"Star pound bang bang, open-paren.
Tilde and pipe, close-paren.
One quote, two quote, dot dot delete,
pound bell, bang bang, process complete!"
-the Pre 1990 post ("Stuck Shift Key Poetry") to rec.humor.funny
httping-1.2.2.tgz
Description: application/tgz
webwatch.pl
Description: Perl program
pgpfpQOGJjb8A.pgp
Description: PGP signature
