3

I tried setting up a crontab on my Mac, but it's not running for some reason.

Here's what I'm trying to run:

*/2 * * * *  /BackupScript/backup.sh

I have it set to every 2 minutes currently for testing purposes. When I add

>> /BackupScript/log.log

to the cron task, it never writes anything to the file, merely creates a blank file. I should add that the script works fine when ran manually.

Where am I going wrong?

7
  • There's not much info to go on in your post - we don't know what your script does, how you start it manually, if it depends on environment variables, ... Try adding 2>&1 at the end of the cron task (in addition to the log redirect) to catch stderr too.
    – Mat
    Jul 21, 2012 at 6:45
  • I run it manually through terminal, by cd'ing to the appropriate directory and running ./backup.sh. The script is intended to simply copy one folder to another location. I'm unsure of what you mean by environment variables- I'm guessing it doesn't depend on any.
    – Erickj92
    Jul 21, 2012 at 6:47
  • Erick, no-one can help you without more information about your script itself and how it is failing. Please try what I mentioned above to get a chance at catching error messages from your cron task.
    – Mat
    Jul 21, 2012 at 6:49
  • Sorry, new to all this. I've tried adding the 2>&1 to the end of the cron task, but to no avail. The script itself isn't failing, it just simply isn't running when the cron job should be telling it to. I was guessing it's some sort of syntax error in my cron job, maybe not spacing something properly or missing something obvious. I've followed many guides online, and it looks like I'm doing everything correctly.
    – Erickj92
    Jul 21, 2012 at 6:52
  • Your original append syntax for stdout works fine for me on a script that contains simply the command date; any stderr is sent to /var/mail/$USER. Have you tried running a trivial script like that instead of your actual script?
    – Deditos
    Jul 21, 2012 at 10:28

1 Answer 1

1

This was fixed by changing the cron job slightly. It was changed from

*/2 * * * *  /BackupScript/backup.sh >> /BackupScript/log.log 2>&1

to

*/2 * * * *  cd /BackupScript && ./backup.sh >> /BackupScript/log.log 2>&1

There was some form of issue where the Cron job didn't know to execute the script, but the new version of it explicitly tells it to.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .