Quantcast
Channel: Append current timestamp on files name from background running command - Ask Ubuntu
Viewing all articles
Browse latest Browse all 2

Answer by terdon for Append current timestamp on files name from background running command

$
0
0

Whether the command is backgrounded or not is irrelevant, all you need to do is add the output of a date call to the file names you are creating. Using the exact same syntax as in your question, you could do:

sshpass -p prakash12 ssh -t -p $1 prakash@localhost \
    './test_new_update_script.sh > /home/log/unit_update_output.$(date '+%F-%T').log \
     2> /home/log/unit_update_error.$(date '+%F-%T').log < /dev/null | 
     echo $! > /home/log/unit_update_pids$(date '+%F-%T') &'

The trick is adding $(date '+%F-%T')., this will return (for example):

$ date '+%F-%T'
2014-04-08-18:54:52

So, the command above will create:

/home/log/unit_update_output.2014-04-08-18:57:02.log 
/home/log/unit_update_error.2014-04-08-18:57:02.log 
/home/log/unit_update_pids2014-04-08-18:57:02

See man date for the different formats you can have.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>