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
©2019-2020 Toolsou All rights reserved,
1190 Reverses the substring between each pair of parentheses leetcodemysql Joint index details You don't know ——HarmonyOS Create data mysql Library process Character recognition technology of vehicle license plate based on Neural Network A guess number of small games , use JavaScript realization Talking about uni-app Page value transfer problem pytorch of ResNet18( Yes cifar10 The accuracy of data classification is achieved 94%)C++ Method of detecting memory leak One is called “ Asking for the train ” A small village Finally got the train