For some reasons, such as the need to check whether there is a switch between the network and other issues, a long time to ping an address, because it will output a lot of information and it is best to have a timestamp, so we can use a simple combination of several shell commands can be achieved: a long time ping an address, Record the time stamp of each ping, and output to the text save, in addition, we can put this action in the background to execute, so as not to log off after being interrupted.
The first is a long time ping, this is very simple, using the parameter-C can be:
[Root@test ~]# Ping 192.168.2.1-c 10
PING 192.168.2.1 (192.168.2.1) bytes of data.
Bytes from 192.168.2.1:icmp_seq=1 ttl=64 time=0.638 ms
Bytes from 192.168.2.1:icmp_seq=2 ttl=64 time=0.341 ms
Bytes from 192.168.2.1:icmp_seq=3 ttl=64 time=0.291 ms
Bytes from 192.168.2.1:icmp_seq=4 ttl=64 time=0.259 ms
Bytes from 192.168.2.1:icmp_seq=5 ttl=64 time=0.338 ms
Bytes from 192.168.2.1:icmp_seq=6 ttl=64 time=0.339 ms
Bytes from 192.168.2.1:icmp_seq=7 ttl=64 time=0.243 ms
Bytes from 192.168.2.1:icmp_seq=8 ttl=64 time=0.234 ms
Bytes from 192.168.2.1:icmp_seq=9 ttl=64 time=0.333 ms
Bytes from 192.168.2.1:icmp_seq=10 ttl=64 time=0.284 ms
---192.168.2.1 ping statistics---
Packets transmitted, received, 0% packet loss, time 9002ms
RTT Min/avg/max/mdev = 0.234/0.330/0.638/0.109 ms
We ping the above 10 times, each time 1 seconds, so for example you want to ping the sky is 60*60*24*2=172800.
The next step is to add time stamps:
Root@test ~]# Ping 192.168.2.1-c 10 | awk ' {print $ ' \ t ' strftime ("%h:%m:%s", Systime ())} '
PING 192.168.2.1 (192.168.2.1) bytes of data. 10:30:21
Bytes from 192.168.2.1:icmp_seq=1 ttl=64 time=0.436 Ms 10:30:21
Bytes from 192.168.2.1:icmp_seq=2 ttl=64 time=0.343 Ms 10:30:22
Bytes from 192.168.2.1:icmp_seq=3 ttl=64 time=0.368 Ms 10:30:23
Bytes from 192.168.2.1:icmp_seq=4 ttl=64 time=0.280 Ms 10:30:24
Bytes from 192.168.2.1:icmp_seq=5 ttl=64 time=0.308 Ms 10:30:25
Bytes from 192.168.2.1:icmp_seq=6 ttl=64 time=0.360 Ms 10:30:26
Bytes from 192.168.2.1:icmp_seq=7 ttl=64 time=0.319 Ms 10:30:27
Bytes from 192.168.2.1:icmp_seq=8 ttl=64 time=0.274 Ms 10:30:28
Bytes from 192.168.2.1:icmp_seq=9 ttl=64 time=0.360 Ms 10:30:29
Bytes from 192.168.2.1:icmp_seq=10 ttl=64 time=0.265 Ms 10:30:30
10:30:30
---192.168.2.1 ping statistics---10:30:30
Packets transmitted, received, 0% packet loss, time 9000ms 10:30:30
RTT Min/avg/max/mdev = 0.265/0.331/0.436/0.052 ms 10:30:30
Then we output the information to the text:
[Root@test ~]# ping 192.168.2.1-c 10 | awk ' {print $ ' \ t ' strftime ("%h:%m:%s", Systime ())} ' >ping.log
[Root@test ~]# Cat Ping.log
PING 192.168.2.1 (192.168.2.1) bytes of data. 10:37:23
Bytes from 192.168.2.1:icmp_seq=1 ttl=64 time=0.398 Ms 10:37:23
Bytes from 192.168.2.1:icmp_seq=2 ttl=64 time=0.288 Ms 10:37:24
Bytes from 192.168.2.1:icmp_seq=3 ttl=64 time=0.465 Ms 10:37:25
Bytes from 192.168.2.1:icmp_seq=4 ttl=64 time=0.310 Ms 10:37:26
Bytes from 192.168.2.1:icmp_seq=5 ttl=64 time=0.275 Ms 10:37:27
Bytes from 192.168.2.1:icmp_seq=6 ttl=64 time=0.247 Ms 10:37:28
Bytes from 192.168.2.1:icmp_seq=7 ttl=64 time=0.339 Ms 10:37:29
Bytes from 192.168.2.1:icmp_seq=8 ttl=64 time=0.270 Ms 10:37:30
Bytes from 192.168.2.1:icmp_seq=9 ttl=64 time=0.297 Ms 10:37:31
Bytes from 192.168.2.1:icmp_seq=10 ttl=64 time=0.289 Ms 10:37:32
10:37:32
---192.168.2.1 ping statistics---10:37:32
Packets transmitted, received, 0% packet loss, time 9000ms 10:37:32
RTT Min/avg/max/mdev = 0.247/0.317/0.465/0.067 ms 10:37:32
Finally, we need to put the task backstage:
[Root@test ~]# nohup Ping 192.168.2.1-c 10 | awk ' {print $ ' \ t ' strftime ("%h:%m:%s", Systime ())} ' >ping1.log &
[1] 2616
[Root@test ~]# ls
Anaconda-ks.cfg check1.sh Desktop eygle.com httpd login pass.conf ping1.log ping.log test1.sh test1.sh1
[Root@test ~]# Cat Ping1.log
PING 192.168.2.1 (192.168.2.1) bytes of data. 10:40:22
Bytes from 192.168.2.1:icmp_seq=1 ttl=64 time=0.373 Ms 10:40:22
Bytes from 192.168.2.1:icmp_seq=2 ttl=64 time=0.343 Ms 10:40:23
Bytes from 192.168.2.1:icmp_seq=3 ttl=64 time=0.335 Ms 10:40:24
Bytes from 192.168.2.1:icmp_seq=4 ttl=64 time=0.299 Ms 10:40:25
Bytes from 192.168.2.1:icmp_seq=5 ttl=64 time=0.372 Ms 10:40:26
Bytes from 192.168.2.1:icmp_seq=6 ttl=64 time=0.236 Ms 10:40:27
Bytes from 192.168.2.1:icmp_seq=7 ttl=64 time=0.394 Ms 10:40:28
Bytes from 192.168.2.1:icmp_seq=8 ttl=64 time=0.317 Ms 10:40:29
Bytes from 192.168.2.1:icmp_seq=9 ttl=64 time=0.490 Ms 10:40:30
Bytes from 192.168.2.1:icmp_seq=10 ttl=64 time=1.65 Ms 10:40:31
10:40:31
---192.168.2.1 ping statistics---10:40:31
Packets transmitted, received, 0% packet loss, time 9001ms 10:40:31
RTT Min/avg/max/mdev = 0.236/0.480/1.650/0.395 ms 10:40:31
Note: nohup Ping 192.168.2.1-c 10 | awk ' {print $ ' \ t ' strftime ("%y-%m-%d%h:%m:%s", Systime ())} ' >ping1.log 2>&1 &
This will print to the file every 4K or so
Turn from: http://blog.csdn.net/gtlions/article/details/7974087