linux - How to prepend timestamp to the STDERR and redirect to a file -


I am redirecting to STDERR only in one file (which is working more or less), but I also add / Want to include a time-ticket for each redirection I do not want time in every line, just at the beginning of the block. I tried to do this:

  UKMAC08: ~ san $ (date1 & gt; & amp; 2; df -jj) 2 & gt; And 1 1> / dev / null 2> testErr.log; Cat testErr.log Friday 1 August 2014 10:50:00 BST DF: Illegal Option - J Usage: DF [-B | -H | -H | -c | -M | -G | -P] [-ailn] [-T type] [-T] [filesystem ...]  

What I'm trying to do for a failed run, but this It's also taking the time when it's a success:

  UKMAC08: ~ san $ (date1 & gt; & amp; 2; df-h) 2 & gt; And 1 1> / dev / null 2> testErr.log; Cat testErr.log Friday 1 August 2014 10:50:07 BST  

How can I avoid this? the best!

This can:

  OUT = $ (df - H2 & gt; and 1> / dev / null) || {Date; Echo "$ out"; } & Gt; TestErr.log  

Test:

  $: & gt; TestErr.log; Out = $ (df -jj 2> and 1> dev / null) || {Date -u; Echo "$ out"; } & Gt; TestErr.log; Cat testErr.log Fri Aug 1 12:10:29 UTC 2014 df: Invalid option - 'J' Try 'df --help' for more information. $: & Gt; TestErr.log; Out = $ (DF-H2> and 1> dev / null) || {Date -u; Echo "$ out"; } & Gt; TestErr.log; Cat testErr.log (no output)  

You can edit the & gt; TestErr.log to gt; & Gt; & Gt; Can replace testErr.log .

And it can be more efficient:

  OUT = $ (exec df-2 2> and 1> dev / null) || {Date; Echo "$ out"; } & Gt; TestErr.log  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -