Add Time To Log File For Cron Job

Home » CentOS » Add Time To Log File For Cron Job
CentOS 2 Comments

Hey all,

I’m trying to figure out a way to insert a timestamp into a log file I’m creating for a cron job I’m setting up:

/usr/bin/rsync -v –min-size=1 -rlpgo -O –inplace /home/myuser/Get*
root@xx.x.xx.xx:/mnt/bravotv/media/compass 2>&1 >& /tmp/rsync_user.log

I’ve googled this but all I could find are tips on how to add the time and date to the name of the log file itself, not to the contents of the log.

Any tips or pointers would be great.

Thanks Tim

2 thoughts on - Add Time To Log File For Cron Job

  • Why not make your rsync command into the second line of a script, and make the first line of the script write the time to the log.

  • Guys,

    This is what worked

    [root@uszmpwsld011 ~]# /usr/bin/rsync -v –min-size=1 -rlpgo -O –inplace
    /home/compassfeeduser/Get* root@xx.xx.xx:/mnt/bravotv/media/compass | ts
    2>&1 >& debug.txt

    [root@uszmpwsld011 ~]# cat debug.txt May 23 23:44:49 sending incremental file list May 23 23:44:49
    May 23 23:44:49 sent 67 bytes received 12 bytes 158.00 bytes/sec May 23 23:44:49 total size is 0 speedup is 0.00

    Thanks to Karl who provided this. Tim