agregar_fecha_a_salida_de_comandos_linea_por_linea
Agregar fecha y hora a cada linea resultante de la ejecución de un comando en GNU/Linux
Usando Perl.
ping 8.8.8.8 | perl -nle 'print scalar(localtime), " ", $_' Tue Sep 18 16:17:22 2018 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. Tue Sep 18 16:17:22 2018 64 bytes from 8.8.8.8: icmp_seq=1 ttl=121 time=2.87 ms Tue Sep 18 16:17:23 2018 64 bytes from 8.8.8.8: icmp_seq=2 ttl=121 time=2.85 ms
Usando Perl y redireccionando a un fichero (/tmp/file).
ping 8.8.8.8 | perl -nle '$|++;print scalar(localtime), " ", $_' > /tmp/file
Comando ts (moreutils).
ping 8.8.8.8 | ts sep 18 16:08:41 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. sep 18 16:08:41 64 bytes from 8.8.8.8: icmp_seq=1 ttl=121 time=3.02 ms sep 18 16:08:42 64 bytes from 8.8.8.8: icmp_seq=2 ttl=121 time=2.85 ms # Redireccionar a fichero no necesita nada especial. ping 8.8.8.8 | ts > /tmp/file
agregar_fecha_a_salida_de_comandos_linea_por_linea.txt · Last modified: 2020/12/25 22:57 by 127.0.0.1