I'm trying to output the current date in this format to a file using /etc/crontab. But crontab doesn't like this formatting. Changing sh to bash doesn't help.
my crontab:
* * * * * root echo "$(date +%F) - $(date +%T) - no sleep!" >> /home/thomas/1-18-WD/ami
expected output to the file: 2021-05-18 - 03:57:09 - no sleep!
it only works if I just do echo "$(date) - no sleep!" The "+" is causing the problem I think.
2>&1
to capture any error output to your file as well – steeldriver May 24 '21 at 21:17root
in your example) is only required in the systemwide /etc/crontab file - if you are using a user-crontab viacrontab -e
orsudo crontab -e
it is wrong and will cause the job to fail. – steeldriver May 25 '21 at 01:00