Sometimes you want to track how long a server is taking to reboot. When you are doing some High Availability test scenario you want to validate how long a Virtual IP is down.
The ping command is good to track if one IP address is up, but the output is not timestamped and you cannot do post-analysis.
We are using one CentOS 8.2:
[moore@mux ~]$ cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
Our command will work with the bash shell:
[moore@mux ~]$ echo $SHELL
/bin/bash
For example, if we want to ping the IP 192.168.1.2, we can use thins one-liner:
[moore@mux ~]$ ping 192.168.1.2 | while read pong; do echo "$(date): $pong"; done
Wed Nov 25 21:06:16 UTC 2020: PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
Wed Nov 25 21:06:16 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=1 ttl=64 time=0.837 ms
Wed Nov 25 21:06:17 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=1.01 ms
Wed Nov 25 21:06:18 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=0.882 ms
Wed Nov 25 21:06:19 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=0.738 ms
Wed Nov 25 21:06:34 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=19 ttl=64 time=1.48 ms
Wed Nov 25 21:06:35 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=20 ttl=64 time=0.675 ms
Wed Nov 25 21:06:36 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=21 ttl=64 time=0.617 ms
Wed Nov 25 21:06:37 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=22 ttl=64 time=0.757 ms
Wed Nov 25 21:06:38 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=23 ttl=64 time=1.00 ms
Wed Nov 25 21:06:39 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=24 ttl=64 time=0.659 ms
^C
We can see in these logs that the IP address 192.168.1.2 was not pinging during 15 seconds from 21:06:19 to 21:06:34.
Once the observation period is over, you can bring the task back to the foreground with the foreground command ‘fg’:
[moore@mux ~]$ ping 192.168.1.2 | while read pong; do echo "$(date): $pong"; done > /tmp/ping_testing.log &
[1] 4900
[moore@mux ~]$ fg
ping 192.168.1.2 | while read pong; do
echo "$(date): $pong";
done > /tmp/ping_testing.log
^C
The ping measurements are well dated and I can do my analysis from the log file:
[moore@mux ~]$ cat /tmp/ping_testing.log
Wed Nov 25 21:41:45 UTC 2020: PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
Wed Nov 25 21:41:45 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=1 ttl=64 time=0.750 ms
Wed Nov 25 21:41:46 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=0.801 ms
Wed Nov 25 21:41:47 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=0.664 ms
Wed Nov 25 21:41:48 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=0.687 ms
Wed Nov 25 21:41:49 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=5 ttl=64 time=0.666 ms
Wed Nov 25 21:41:50 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=6 ttl=64 time=0.741 ms
Wed Nov 25 21:41:52 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=7 ttl=64 time=0.803 ms
Wed Nov 25 21:41:53 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=8 ttl=64 time=0.804 ms
Wed Nov 25 21:41:54 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=9 ttl=64 time=0.689 ms
Wed Nov 25 21:41:55 UTC 2020: 64 bytes from 192.168.1.2: icmp_seq=10 ttl=64 time=0.616 ms