GawkING Data from Ping


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting GawkING Data from Ping
# 1  
Old 09-16-2014
GawkING Data from Ping

I am trying to cut out the "time" in the ttl field from:
Code:
64 bytes from 4.2.2.5: icmp_seq=1 ttl=54 time=26.2 ms
64 bytes from 4.2.2.5: icmp_seq=2 ttl=54 time=20.5 ms
64 bytes from 4.2.2.5: icmp_seq=3 ttl=54 time=26.5 ms
64 bytes from 4.2.2.5: icmp_seq=4 ttl=54 time=29.8 ms
^C

and am having a little trouble doing so. When I attempt to use GAWK like:
Code:
ping 4.2.2.4 | gawk -F ' ' '{IGNORECASE=1;} /time/ {print $(NF-1)}'
time=37.1
time=32.8
time=37.2
time=34.4
^C

I cannot isolate just the digits using the cut command:
Code:
ping 4.2.2.4 | gawk -F ' ' '{IGNORECASE=1;} /time/ {print $(NF-1)}'| cut -c 5-

it simply produced nothing. I have tried many different variables and cannot figure out what it is. Why is the cut command not doing what I am asking it to do. I would like it to produce:
Code:
37.1
32.8
37.2
34.4

at the end of the day I would have a one-liner something like this;
Code:
for r in *; do (ping 4.2.2.4 | gawk -F ' ' '{IGNORECASE=1;} /time/ {print $7}'| cut -c 5-);if [ $r -ge 50 ] echo "ttl time is greater that 50" fi;done


Last edited by metallica1973; 09-16-2014 at 03:52 PM..
# 2  
Old 09-16-2014
Code:
$ ping -c 4 66.82.4.8 | awk -F" " '/time/ { T=substr($(NF-1),6)+0 ; if(T>50) print T }'
69.5
69.8
69.4
69.5

$

# 3  
Old 09-16-2014
Another approach:-
Code:
ping -c 4 66.82.4.8 | gawk -F'[= ]' '/time=/&&$(NF-1)>=50{print $(NF-1)}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Ping test sends mail when ping fails

help with bash script! im am working on this script to make sure my server will stay online, so i made this script.. HOSTS="192.168.138.155" COUNT=4 pingtest(){ for myhost in "$@" do ping -c "$COUNT" "$myhost" &&return 1 done return 0 } if pingtest $HOSTS #100% failed... (4 Replies)
Discussion started by: mort3924
4 Replies

2. Shell Programming and Scripting

How to get reason for ping failure using perls Net::Ping->new("icmp");?

Hi I am using perl to ping a list of nodes - with script below : $p = Net::Ping->new("icmp"); if ($p->ping($host,1)){ print "$host is alive.\n"; } else { print "$host is unreacheable.\n"; } $p->close();... (4 Replies)
Discussion started by: tavanagh
4 Replies

3. IP Networking

PING

I am unable to ping my remote server.My server is unable to ping the same. both are able to ping the gateway. both the ip's are on same network.i use a proxy tunnel on my remote server.Help if any clues. (6 Replies)
Discussion started by: oslbhavana
6 Replies

4. Shell Programming and Scripting

Animation Ping on Solaris Like Cisco Ping

Hi, I develop simple animation ping script on Solaris Platform. It is like Cisco ping. Examples and source code are below. bash-3.00$ gokcell 152.155.180.8 30 Sending 30 Ping Packets to 152.155.180.8 !!!!!!!!!!!!!.!!!!!!!!!!!!!!!. % 93.33 success... % 6.66 packet loss...... (1 Reply)
Discussion started by: gokcell
1 Replies

5. Shell Programming and Scripting

Router ping log extract data from it Awk/Sed/grep

Hi, I am new to this world.. Using expect i loging to router and checking ping response to my links. I need to genarate report using this output and that report contains only three file link name, packet loss, latency. my output of script is like below: -bash-3.00$ monmw/mwbkp... (2 Replies)
Discussion started by: jkmistry
2 Replies

6. Solaris

Ping

Hi, I was trying to ping the source and destination i.ps ping -i <source> <destination> <destination> is alive Now i would like to see the packets contiuosly. Please suggest what option can be used with ping command to see For example if i give PING 10.137.58.78: 56 data bytes 64... (3 Replies)
Discussion started by: kkarthik_kaja
3 Replies

7. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

8. IP Networking

Command to ping 1500 bytes of data to a destination system

Hi All, I want to ping 1500 bytes of data from a pc to another pc in the network. What is command used for the same? Thanks (2 Replies)
Discussion started by: rvan
2 Replies

9. Linux

Not able to ping

Hi All, Need your help one more time. I am trying to ping a linux machine which is not responding to ping. However traceroute can reach the machine and I can log in to it by ssh. I have checked /proc/sys/net/ipv4/icmp_echo_ignore_all it is already set as "0". It is not happening in the... (1 Reply)
Discussion started by: ailnilanjan
1 Replies

10. Shell Programming and Scripting

ping -t

I need a script that recieves an IP adress and a number of seconds as arguments. and display a massage if the IP replies or not. (8 Replies)
Discussion started by: jaber87
8 Replies
Login or Register to Ask a Question