Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Maybe move the >> operator before "$logfile" to append to the log, though it's not clear if OP wants to overwrite or append... Commented Nov 7, 2019 at 19:55
  • @Freddy, hmm, they did have just 1>$LOGFILE in the Q, and with a timestamped log the file probably doesn't exist anyway. The redirection to the process substitution could of course be just 1> >(...), but that doesn't matter either... Commented Nov 7, 2019 at 20:09
  • Unfortunately I have to use date as ts is not available and I can't easily obtain it (firewalls, other corporate stuff). I have tried this: exec 1>> >(date '+[%Y-%m-%d %I:%M:%S %p]: ' > "$logfile") 2>&1 but all I get is a single line with the date output and nothing else. Commented Nov 7, 2019 at 21:46
  • @sc_0987, yes, date would just output the date once. what you need is a program that reads the input and passes it through with the date added. Did you look at the linked question? There's another answer there with more ways to do it, e.g. with Perl or just the shell and date. (Of course you'll have to replace the pipe structure with the process substitution) Commented Nov 7, 2019 at 21:51