Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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:

0   20  *   *   *   /data/code/scripts/foo.sh >/root/foo.`date +\%Y-\%m-\%d-\%T`.log 2>&1

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.

share|improve this answer

You will possibly also need to use the full path to the date command.

It's probably located at /bin/date, you can check where it is on your box with which date.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.