Include script runtime date in cron logs

From miscellus

Include script runtime date in cron logs

File:Include script runtime date in cron logs.jpg
Include script runtime date in cron logs

If you need to include the current time and date when a cron job runs in the logs, use this simple command:

( /bin/date && /path/to/cronjob >> /path/to/cron-logfile 2>&1

or a real life example:

( /bin/date && /usr/bin/tweet-my-thoughts.job >> /var/log/backups/tweet-thoughts.log 2>&1

Output of backup-logfile:

Tue Jan 19 17:15:02 UTC 2021
Tweeting my random thoughts..


If you need to get clever with timestamp formats don't forget to escape any percent symbols %

eg: date "+%Y-%m-%d_%H-%M"

Must be escaped, thus:

date "+\%Y-\%m-\%d_\%H-\%M"


#crontimestamp #crondatelogs #crondate #datecron #cronruntime #cron #date #timestamp #fedora