need bash script to ping a server then traceroute if ping's too slow then mail?

Hi there.

Quick q please.

I need a bash script that will ping a server 5 times, analyse the results and figure out an average ping time then, if it's too long a time, initiate a traceroute to that server, and finally mail the results of the traceroute to me.

Any ideas please?

thanks

Daryn
darynAsked:
Who is Participating?
 
ravenplCommented:
IP=1.2.3.4
AVGMAX=200 #miliseconds
AVGLINE=$( ping -w6 -c5 $IP | grep "rtt min/avg/max/mdev" )
if [ -z "$AVGLINE" ]; then
 AVG=$(echo $A | cut -d/ -f5 | cut -d. -f1)
else
  AVG=$AVGMAX
fi

if [ $AVG -ge $AVGMAX ]; then
 #possibly You could add more options
 /usr/sbin/traceroute $IP | mail -s "AVG=$AVG, running traceroute" You@address.tld
fi
0
 
ravenplCommented:
line: AVG=$(echo $A | cut -d/ -f5 | cut -d. -f1)
should be: AVG=$( echo $AVGLINE | cut -d/ -f5 | cut -d. -f1 )
0
 
ahoffmannCommented:
ping -c 5 -w 5 server | awk -F/ '/^rtt/{if($5>0.5){print "traceroute server"}}' | sh | mail -s"server AVG" you@domain.tld
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
m1tk4Commented:
what you really should be using is http://www.nagios.org/
0
 
ahoffmannCommented:
m1tk4, do you really need sophisticated/complicated software packages for simple things being done in a one liner ?-)
Anyway, let the questioner decide, another suggestion: http://www.bb4.com/ http://bb4.org/
0
 
m1tk4Commented:
>>m1tk4, do you really need sophisticated/complicated software packages for simple things being done in a one liner ?-)

Do people really need Microsoft Word when most of what they do can be done in Notepad? :)) Nagios is pretty easy to install/tune, actually.
0
 
ahoffmannCommented:
> when most of what they do can be done in Notepad?
Notepad? you mean vi
*SCNR*
0
 
m1tk4Commented:
vi is for sissies. real men use emacs. However, we've got too far from the question;))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.