LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

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

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


hi,
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?

Thanks
 
Old 05-19-2008, 10:08 AM   #2
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 492

Rep: Reputation: 50
Maybe something like:
Code:
#!/bin/sh
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, 01:51 PM   #3
brgsousa
Member
 
Registered: Aug 2007
Location: Salvador, Brazil
Distribution: Debian, Ubuntu
Posts: 185

Original Poster
Rep: Reputation: 15
Thanks

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

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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?
 
  


Reply

Tags
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 05:54 PM
Return code of a shell script zachos.v Linux - Software 3 10-10-2006 09:51 AM
Return value to shell in script mwade Linux - Newbie 11 08-18-2006 09:49 AM
return value from shell script to c code? khucinx Programming 1 05-13-2004 03:43 PM
return key on shell script chupacabra Programming 2 10-22-2002 12:11 PM


All times are GMT -5. The time now is 02:28 AM.

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