Ping Average Time

Functions, Variables, String Operators, Command Substitution, Arrays, if/else, while/until, for, case, select, I/O Redirectors, String I/O, Process ID's, Job Control, trap, signals, subshells, debugging.,

Ping Average Time

Postby abakhiet » Tue Mar 09, 2010 12:57 am

hi all,
I need to ask, how using bash i can do ping for 10 times and get the Average time to put it in some variable ???
abakhiet
 
Posts: 4
Joined: Tue Mar 09, 2010 12:54 am
Location: Assiut, Egypt

Re: Ping Average Time

Postby abakhiet » Tue Mar 09, 2010 1:05 am

i forget to say, that i will use this time average to make some processes to make a certain job :D
abakhiet
 
Posts: 4
Joined: Tue Mar 09, 2010 12:54 am
Location: Assiut, Egypt

Re: Ping Average Time

Postby DarthWavy » Tue Mar 09, 2010 4:22 am

The following should display the average time;

Code: Select all
ping -qc 10 localhost | awk -F/ '/^rtt/ { print $5 }'


Of course this assumes that your ping outputs like the one I'm using.
If this doesn't seem to work then post the output of "ping -qc 10 localhost"

=:)
User avatar
DarthWavy
 
Posts: 151
Joined: Thu Oct 11, 2007 7:12 am
Location: London - UK

Re: Ping Average Time

Postby abakhiet » Tue Mar 09, 2010 6:17 am

thanks for your time, but i need to put $5 variable in some new parameter named y...
abakhiet
 
Posts: 4
Joined: Tue Mar 09, 2010 12:54 am
Location: Assiut, Egypt

Re: Ping Average Time

Postby DarthWavy » Wed Mar 10, 2010 7:59 am

There are many many many many examples of how to do that, but here it is again;

Code: Select all
myvar="$(ping -qc 10 localhost | awk -F/ '/^rtt/ { print $5 }')"
User avatar
DarthWavy
 
Posts: 151
Joined: Thu Oct 11, 2007 7:12 am
Location: London - UK


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron