This is the cron job I'm trying to run nightly:
0 20 * * * /data/code/scripts/foo.sh >/root/foo.$(date +%Y-%m-%d-%T).log 2>&1
When I run it from the command line, it works fine. But Cron doesn't appear to even try and run it.
Thoughts?
cron
This is the cron job I'm trying to run nightly:
0 20 * * * /data/code/scripts/foo.sh >/root/foo.$(date +%Y-%m-%d-%T).log 2>&1
When I run it from the command line, it works fine. But Cron doesn't appear to even try and run it.
Thoughts?
Best Answer
The % symbols need to be escaped in cron jobs.
Put a backslash in front of each one.
Late edit:
I'm not sure how I missed this before but you are using a bash syntax for creating a subshell to run your
date
command in. Since cron is not bash, this won't work. It will work if you change your cron job to this:Alternatively, you could do the output redirection from within the script or (if that's not appropriate) write a wrapper script that calls the above one and does the output redirection.