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

Advertisement

Leave a Comment »

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.

Follow

Get every new post delivered to your Inbox.