In Linux, ping the network for a long time, add a timestamp, and record the timestamp to the text.

Source: Internet
Author: User


In Linux, ping the network for a long time and add a timestamp and record it to the text. For example, you need to check whether a packet is dropped between the networks and ping an address for a long time,
Since a large amount of information is output and it is better to have a timestamp, we can use a few simple shell command combinations.
We can achieve this: ping an address for a long time, record the timestamp of each ping, and output it to the text for saving. In addition, we can
You can also put this action in the background to avoid interruption after logging out. The first step is Long ping. This is very simple. Use the-c parameter:
[Root @ test ~] # Ping 192.168.2.1-c 10 PING 192.168.2.1 (192.168.2.1) 56 (84) bytes of data.64 bytes from 192.168.2.1: icmp_seq = 1 ttl = 64 time = 0.638 ms64 bytes from 192.168.2.1: icmp_seq = 2 ttl = 64 time = 0.341 ms64 bytes from 192.168.2.1: icmp_seq = 3 ttl = 64 time = 0.291 ms64 bytes from 192.168.2.1: icmp_seq = 4 ttl = 64 time = 0.259 ms64 bytes from 192.168.2.1: icmp_seq = 5 ttl = 64 time = 0.338 ms64 bytes from 192.168.2.1: icmp_se Q = 6 ttl = 64 time = 0.339 ms64 bytes from 192.168.2.1: icmp_seq = 7 ttl = 64 time = 0.243 ms64 bytes from 192.168.2.1: icmp_seq = 8 ttl = 64 time = 0.234 ms64 bytes from 192.168.2.1: icmp_seq = 9 ttl = 64 time = 0.333 ms64 bytes from 192.168.2.1: icmp_seq = 10 ttl = 64 time = 0.284 MS --- 192.168.2.1 ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 9002 msrtt min/avg/max/mdev = 0.234/0.330/0.638/0. We pinged 10 times in 109 ms, and each time it took 1 second. Therefore, for example, if you want to ping for a day, it would be 60*60*24*2 = 172800. Next, add the timestamp: root @ test ~]. # Ping 192.168.2.1-c 10 | awk '{print $0 "\ t" strftime ("% H: % M: % S", systime ())} 'Ping 192.168.2.1 (192.168.2.1) 56 (84) bytes of data. 10: 30: 2164 bytes from 192.168.2.1: icmp_seq = 1 ttl = 64 time = 0.436 MS 10: 30: 2164 bytes from 192.168.2.1: icmp_seq = 2 ttl = 64 time = 0.343 MS 10: 30: 2264 bytes from 192.168.2.1: icmp_seq = 3 ttl = 64 time = 0.368 MS 10: 30: 2364 bytes from 192.168.2.1: icmp_seq = 4 ttl = 64 time = 0.280 MS 10: 30: 2464 bytes from 192.168.2.1: icmp_seq = 5 ttl = 64 time = 0.308 MS 10: 30: 2564 bytes from 192.168.2.1: icmp_seq = 6 ttl = 64 time = 0.360 MS 10: 30: 2664 bytes from 192.168.2.1: icmp_seq = 7 ttl = 64 time = 0.319 MS 10: 30: 2764 bytes from 192.168.2.1: icmp_seq = 8 ttl = 64 time = 0.274 MS 10: 30: 2864 bytes from 192.168.2.1: icmp_seq = 9 ttl = 64 time = 0.360 MS 10: 30: 2964 bytes from 192.168.2.1: icmp_seq = 10 ttl = 64 time = 0.265 Ms 10:30:30 --- 192.168.2.1 ping statistics --- 10:30:30 packets transmitted, 10 bytes ed, 0% packet loss, time 9000 ms 10: 30: 30rtt 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 $0 "\ t" strftime ("% H: % M: % S", systime ()}'> ping. log www.2cto.com [root @ test ~] # Cat ping. logPING 192.168.2.1 (192.168.2.1) 56 (84) bytes of data. 10: 37: 2364 bytes from 192.168.2.1: icmp_seq = 1 ttl = 64 time = 0.398 MS 10: 37: 2364 bytes from 192.168.2.1: icmp_seq = 2 ttl = 64 time = 0.288 MS 10: 37: 2464 bytes from 192.168.2.1: icmp_seq = 3 ttl = 64 time = 0.465 MS 10: 37: 2564 bytes from 192.168.2.1: icmp_seq = 4 ttl = 64 time = 0.310 MS 10: 37: 2664 bytes from 192.168.2.1: icmp_seq = 5 ttl = 64 time = 0.275 MS 10: 37: 2764 bytes from 192.168.2.1: icmp_seq = 6 ttl = 64 time = 0.247 MS 10: 37: 2864 bytes from 192.168.2.1: icmp_seq = 7 ttl = 64 time = 0.339 MS 10: 37: 2964 bytes from 192.168.2.1: icmp_seq = 8 ttl = 64 time = 0.270 MS 10: 37: 3064 bytes from 192.168.2.1: icmp_seq = 9 ttl = 64 time = 0.297 MS 10: 37: 3164 bytes from 192.168.2.1: icmp_seq = 10 ttl = 64 time = 0.289 MS 10:37:32 --- 192.168.2.1 ping statistics --- 10:37:32 Packets transmitted, 10 received, 0% packet loss, time 9000 ms 10: 37: 32rtt min/avg/max/mdev = 0.247/0.317/0.465/0.067 ms 10:37:32 last, we need to put the task in the background: [root @ test ~] # Nohup ping 192.168.2.1-c 10 | awk '{print $0 "\ t" strftime ("% H: % M: % S", systime ())} '> ping1.log & [1] 2616 [root @ test ~] # Lsanaconda-ks.cfg check1.sh Desktop eygle.com httpd login pass. conf ping1.log ping. log test1.sh test1.sh1 www.2cto.com [root @ test ~] # Cat ping1.log PING 192.168.2.1 (192.168.2.1) 56 (84) bytes of data. 10: 40: 2264 bytes from 192.168.2.1: icmp_seq = 1 ttl = 64 time = 0.373 MS 10: 40: 2264 bytes from 192.168.2.1: icmp_seq = 2 ttl = 64 time = 0.343 MS 10: 40: 2364 bytes from 192.168.2.1: icmp_seq = 3 ttl = 64 time = 0.335 MS 10: 40: 2464 bytes from 192.168.2.1: icmp_seq = 4 ttl = 64 time = 0.299 MS 10: 40: 2564 bytes from 192.168.2.1: icmp_seq = 5 ttl = 64 time = 0.372 MS 10: 40: 2664 bytes from 192.168.2.1: icmp_seq = 6 ttl = 64 time = 0.236 MS 10: 40: 2764 bytes from 192.168.2.1: icmp_seq = 7 ttl = 64 time = 0.394 MS 10: 40: 2864 bytes from 192.168.2.1: icmp_seq = 8 ttl = 64 time = 0.317 MS 10: 40: 2964 bytes from 192.168.2.1: icmp_seq = 9 ttl = 64 time = 0.490 MS 10: 40: 3064 bytes from 192.168.2.1: icmp_seq = 10 ttl = 64 time = 1.65 ms 10:40:31 --- 192.168.2.1 ping statistics --- 10:40:31 packets transmitted, 10 received, 0% packet loss, time 9001 ms 10: 40: 31rtt min/avg/max/mdev = 0.236/0.480/1.650/0.395 MS 10:40:31-The End-

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.