How to add timestamp to STDERR redirection

后端 未结 13 2504
感情败类
感情败类 2020-11-28 05:10

In bash/ksh can we add timestamp to STDERR redirection?

E.g. myscript.sh 2> error.log

I want to get a timestamp written on the log too.

13条回答
  •  借酒劲吻你
    2020-11-28 05:36

    The program ts from the moreutils package pipes standard input to standard output, and prefixes each line with a timestamp.

    To prefix stdout lines: command | ts
    To prefix both stdout and stderr: command 2>&1 | ts

提交回复
热议问题