A veces quieres saber cuánto tiempo tarda un servidor en reiniciarse. Cuando se ejecuta un caso de prueba de alta disponibilidad, se quiere validar el tiempo de inactividad de una IP virtual.
El comando ping es útil para rastrear si un servidor está activo, pero la salida no tiene fecha y no se puede hacer un análisis posterior.
Estamos usando un CentOS 8.2:
[moore@mux ~]$ cat /etc/redhat-release
CentOS Linux release 8.2.2004 (Core)
Nuestro comando trabajará con el shell bash:
[moore@mux ~]$ echo $SHELL
/bin/bash
Por ejemplo, si queremos hacer un ping a la dirección IP 192.168.1.2, podemos usar esta línea de comandos:
[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
Podemos ver en estos registros que la dirección IP 192.168.1.2 no respondió durante un agujero negro de 15 segundos de 21:06:19 a 21:06:34.
Una vez que el período de observación haya terminado, puedes traer la tarea de vuelta al primer plano con el comando de primer plano “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
[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