Only pipe STDERR output in
bash with timestamp
In order to discard standard output and only log the standard error, following command can be used. The second part of command is to prefix the current timestamp in the output
sh monitor 2>&1>/dev/null | ts '[%Y-%m-%d %H:%M:%S]'
If need to run in
dash, such as running in
crontab, above syntax is wrong, use following command instead
sh monitor 3>&1 1>/dev/null 2>&3 3>&- | ts '[%Y-%m-%d %H:%M:%S]'
Note: This command can be run in