-4
[root@test143 ~]# ping 8.8.8.8 | while read xx; do echo "$(date '+%Y-%m-%d %H:%M:%S'): $xx"; done
2016-06-30 15:51:41: PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
2016-06-30 15:51:41: 64 bytes from 8.8.8.8: icmp_seq=1 ttl=47 time=78.2 ms
2016-06-30 15:51:43: 64 bytes from 8.8.8.8: icmp_seq=3 ttl=47 time=78.2 ms
2016-06-30 15:51:44: 64 bytes from 8.8.8.8: icmp_seq=4 ttl=47 time=78.3 ms
...
2016-06-30 15:57:58: 64 bytes from 8.8.8.8: icmp_seq=300 ttl=47 time=78.4 ms

I want to monitor the network interrupt(centos 6.5). As mentioned above,we lost icmp_seq=2,How to locate the gap.

1 Answers1

0

Search Stack again...

Say you have an input file named gaps

more gaps
icmp_seq=1
icmp_seq=2
icmp_seq=3
icmp_seq=5
icmp_seq=8
icmp_seq=10

You can make use of the below AWK

awk -F "=" '$2!=p+1{print p+1"-"$2-1}{p=$2}' gaps
4-4
6-7
9-9

explanations

-F "=" use = as the field separator
$2 is the second column from current input line
p is the previous value of the last line
so ($2!=p+1) is a condition : if $2 is different than previous value +1, then :
this part is executed : {print p+1 "-" $2-1} : print previous value +1, the - character and second columns + 1
{p=$2} is executed for each lines : p is assigned to the current 2nd column
Community
  • 1
  • 1
Srini V
  • 11,045
  • 14
  • 66
  • 89