Hi,

I was looking for a way to timestamp output from a serial port when I stumbled onto a tool that I'd never heard of. The ts command, which is part of moreutils, will place a timestamp in front of each line of output from stdout.

This:
echo -e "foo\nbar\nbaz" | ts '[%Y-%m-%d %H:%M:%S]'

yields something like this:
[2021-07-27 13:37:36] foo
[2021-07-27 13:37:36] bar
[2021-07-27 13:37:36] baz


Combined with picocom and tee, my logging command looks like this:

picocom -b 9600 /dev/ttyUSB0 | ts '[%Y-%m-%d %H:%M:%S]' | tee "example_$(date +"%Y%m%d%H%M%S").log"

moreutils contains about a dozen other commands which might come in handy at some point.

<https://joeyh.name/code/moreutils/>

galen
--
Galen Seitz
[email protected]

Reply via email to