If you want to achieve ping Add time information , And then save it to a file in real time , Well, then awk combination
1, only need ping information
[root@zhang pingbackage]# ping 115.239.211.112 PING 115.239.211.112
(115.239.211.112) 56(84) bytes of data. 64 bytes from 115.239.211.112:
icmp_seq=1 ttl=53 time=27.1 ms 64 bytes from 115.239.211.112: icmp_seq=2 ttl=53
time=27.0 ms 64 bytes from 115.239.211.112: icmp_seq=3 ttl=53 time=27.1 ms 64
bytes from 115.239.211.112: icmp_seq=4 ttl=53 time=27.0 ms 64 bytes from
115.239.211.112: icmp_seq=5 ttl=53 time=27.0 ms
2, The command line prints and adds time information
[root@zhang pingbackage]# ping 115.239.211.112 | awk '{ print $0"\t"
strftime("%Y-%m-%d %H:%M:%S",systime())}' PING 115.239.211.112
(115.239.211.112) 56(84) bytes of data. 2017-03-25 18:01:07 64 bytes from
115.239.211.112: icmp_seq=1 ttl=53 time=27.1 ms 2017-03-25 18:01:07 64 bytes
from 115.239.211.112: icmp_seq=2 ttl=53 time=27.1 ms 2017-03-25 18:01:08 64
bytes from 115.239.211.112: icmp_seq=3 ttl=53 time=27.0 ms 2017-03-25
18:01:09 64 bytes from 115.239.211.112: icmp_seq=4 ttl=53 time=27.0 ms
2017-03-25 18:01:10 64 bytes from 115.239.211.112: icmp_seq=5 ttl=53 time=27.0
ms 2017-03-25 18:01:11
3, Print this information to a file
[root@zhang pingbackage]# ping 115.239.211.112 | awk '{ print $0"\t"
strftime("%Y-%m-%d %H:%M:%S",systime()); fflush()}' >> outIP.info & [2] 13707
be careful : use fflush() , Otherwise, there will be no information in the file , because awk There is also a cache .
Technology
Daily Recommendation