Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 05-19-2008, 10:54 AM   #1
Registered: Aug 2007
Location: Salvador, Brazil
Distribution: Debian, Ubuntu
Posts: 185

Rep: Reputation: 15
Using ping's return in a shell script

I am writing a shell script for debian that monitors network servers. This script must ping the hosts periodically. It should use ping's output for the monitoring. How can I obtain the time response average and the number of sucessful pings, so that i can use these numbers in the script?

Old 05-19-2008, 11:08 AM   #2
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
Maybe something like:
PING_OUT=`ping -c "$NB_OF_PING" -q "$IP_ADDR"`
min=`echo "$PING_OUT" | awk -F"/" '{print $4}'`
avg=`echo "$PING_OUT" | awk -F"/" '{print $5}'`
max=`echo "$PING_OUT" | awk -F"/" '{print $6}'`
mdv=`echo "$PING_OUT" | awk -F"/" '{print $7}'`
# then $min, $avg, $max and $mdv are the ping output
but i'm not sure you can do arithmetic on float numbers, maybe you have to use bc
Old 05-28-2008, 02:51 PM   #3
Registered: Aug 2007
Location: Salvador, Brazil
Distribution: Debian, Ubuntu
Posts: 185

Original Poster
Rep: Reputation: 15

Thanks man, it really worked.
I had a doubt about mdev. what is this?
Old 05-28-2008, 03:19 PM   #4
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Do you mean this?
min/avg/max/mdev = 1.713/1.713/1.713/0.000 ms

It looks like mdev is the deviation---ie the amount of spread in the distribution. What does "man ping" say?


debian, linux, monitor, ping, script, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
can a C function return value to Shell Script variable yarnar Programming 17 06-02-2010 06:54 PM
Return code of a shell script zachos.v Linux - Software 3 10-10-2006 10:51 AM
Return value to shell in script mwade Linux - Newbie 11 08-18-2006 10:49 AM
return value from shell script to c code? khucinx Programming 1 05-13-2004 04:43 PM
return key on shell script chupacabra Programming 2 10-22-2002 01:11 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:29 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration