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,
【 Explain in detail 】 Interview must ask :SpringBoot Automatic configuration principle 【 Hyper detail 】Java Realization of student information management system 2020 The 11th National Blue Bridge Cup Python group JavaScript note ( five )---- Branch statement MYSQL database SQL Sentence practice experiment EXERCISES. 1 SIMPLE COMMANDSMySQL Basics Commonly used sentence ( Add / delete / modify query )C++ of string of compare usage vue limit input Only positive numbers can be entered C Language of a Gobang game implementation Programmer refused due to low salary offer,HR become shame , Netizens instantly blew up ..