How to add timestamp to STDERR redirection

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

    If you want to redirect back to stdout I found you have to do this:

    myscript.sh >> >( while read line; do echo "$(date): ${line}"; done )
    

    Not sure why I need the > in front of the (, so <(, but thats what works.

提交回复
热议问题