Par défaut, la commande ping n'affiche pas la date et l'heure :
root@mypc:~# ping www.google.fr
PING www.google.fr (173.194.34.23) 56(84) bytes of data.
64 bytes from par03s02-in-f23.1e100.net (173.194.34.23): icmp_req=1 ttl=52 time=45.0 ms
64 bytes from par03s02-in-f23.1e100.net (173.194.34.23): icmp_req=2 ttl=52 time=43.0 ms
64 bytes from par03s02-in-f23.1e100.net (173.194.34.23): icmp_req=3 ttl=52 time=40.1 ms
Une ligne de commande permet de remédier à ce problème :
ping www.google.fr | while read pong; do echo "$(date): $pong"; done
Le résultat est alors :
root@mypc:~# ping www.google.fr | while read pong; do echo "$(date): $pong"; done
vendredi 15 mars 2013, 09:30:47 (UTC+0100): PING www.google.fr (173.194.34.24) 56(84) bytes of data.
vendredi 15 mars 2013, 09:30:47 (UTC+0100): 64 bytes from par03s02-in-f24.1e100.net (173.194.34.24): icmp_req=1 ttl=52 time=79.1 ms
vendredi 15 mars 2013, 09:30:48 (UTC+0100): 64 bytes from par03s02-in-f24.1e100.net (173.194.34.24): icmp_req=2 ttl=52 time=45.6 ms
vendredi 15 mars 2013, 09:30:49 (UTC+0100): 64 bytes from par03s02-in-f24.1e100.net (173.194.34.24): icmp_req=3 ttl=52 time=42.4 ms