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,
c Language implementation 《 Student management system 》 No hole is the future of mobile phone ? There are still many problems to be solved Junior , A little sense , Just for mutual encouragement How to use Vue Used in Echarts Visual Library The 11th Blue Bridge Cup Java The second provincial competition B Group part Python- be based on OpenCV Contour fill for flooding algorithm hole filling 【C#】 The realization of student achievement information management system List Common interview questions in the collection and simple ideas China Mobile Science Popularization : Why do mobile networks call “ Cellular mobile network ”【Golang Basic series 10 】Go language On conditional sentences if