[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-04-27
10
Medium Priority
?
468 Views
Last Modified: 2008-01-16
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
0
Comment
Question by:daryn
  • 3
  • 3
  • 2
8 Comments
 
LVL 43

Accepted Solution

by:
ravenpl earned 272 total points
ID: 16552061
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
 
LVL 43

Expert Comment

by:ravenpl
ID: 16552081
line: AVG=$(echo $A | cut -d/ -f5 | cut -d. -f1)
should be: AVG=$( echo $AVGLINE | cut -d/ -f5 | cut -d. -f1 )
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 264 total points
ID: 16557577
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
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
LVL 15

Assisted Solution

by:m1tk4
m1tk4 earned 264 total points
ID: 16557695
what you really should be using is http://www.nagios.org/
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16559514
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
 
LVL 15

Expert Comment

by:m1tk4
ID: 16561851
>>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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 16562175
> when most of what they do can be done in Notepad?
Notepad? you mean vi
*SCNR*
0
 
LVL 15

Expert Comment

by:m1tk4
ID: 16563332
vi is for sissies. real men use emacs. However, we've got too far from the question;))
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Integration Management Part 2
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question