How to add timestamp to STDERR redirection

后端 未结 13 2481
感情败类
感情败类 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:24

    The devscripts package in Debian/Ubuntu contains a script called annotate-output which does that (for both stdout and stderr).

    $ annotate-output make
    21:41:21 I: Started make
    21:41:21 O: gcc -Wall program.c
    21:43:18 E: program.c: Couldn't compile, and took me ages to find out
    21:43:19 E: collect2: ld returned 1 exit status
    21:43:19 E: make: *** [all] Error 1
    21:43:19 I: Finished with exitcode 2
    

提交回复
热议问题