script for ping and write it to log,if down ur server only
January 31, 2011 at 7:28 am | Posted in shell script | Leave a comment# ping a site if no response then email a message
site=”your ip”
logfile=”/home/hariprakash/pinglog”
pagefile=”/home/hariprakash/down”
pagesite=”your ip”
ping -c 2 $site > /dev/null
#if 100% packet loss – a bad ping
if [ $? -gt 0 ]
then echo bad ping to $site on `date` >>$logfile
#can we connect to the mail server or some other outside server?
ping -c 2 $pagesite
# if we can’t ping the outside, then record so
if [ $? -gt 0 ]
then echo bad ping to $pagesite on `date` >> $logfile
fi
# go ahead and email.. will get it sooner or later
#cat $pagefile |sendmail -t
# instead of sendmail, you could use mail
cat $pagefile | mail -s ” mail server “your ipdaddress” site is down” hari.prakash@tnq.co.in
else touch “$logfile”
fi
we need to add the below content to “down” file
hariprakash@test-server:~$ vim down
From: a_valid_email_address
TO: a_valid_email_address
Subject: URDOWN
We can not ping
your IP/name server..
just u use command
touch pinglog
Leave a Comment »
RSS feed for comments on this post. TrackBack URI
Leave a Reply
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.