-   Linux - Software (
-   -   Using ping's return in a shell script (

brgsousa 05-19-2008 10:54 AM

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?


jf.argentino 05-19-2008 11:08 AM

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

brgsousa 05-28-2008 02:51 PM

Thanks man, it really worked.
I had a doubt about mdev. what is this?

pixellany 05-28-2008 03:19 PM

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?

All times are GMT -5. The time now is 01:30 PM.