shell script doesn't run from cron any more

johnc8117

Registered
hi there

I have a shell script which doesn't run from cron any more for some reason and I'm too stupid to figure out why :) basically this shell script does a backup of some files and uploads them to my server via rsync. The script works ok if I run it from the terminal, but it doesn't work via cron. I ran a small cron script to write out to a tmp file and that worked, so I *think* that cron is running, but I'm now stuck as to what to do. Here are some thoughts:

1) where would the cron or rsync logs be - if any? I looked in /var/log/ but couldn't see any

2) I don't know rsync that well - I think there's a method of writing out a log file. Any help here would be appreciated as then I could see if its even attempting to run this backup

Any suggestions, help etc appreciated

thanks

John
 
I have no idea if this is helpful at all, but.... Just out of curiosity, when you say it doesn't work anymore, did you recently install Tiger? Tiger comes with launchd, which is Apple's own replacement for cron. It makes me wonder if cron even works any more. If you are on Tiger, I'd look into using launchd to see if that makes a difference. If not, do any other cron items run? Check the log information available in /var/log/daily.out (and elsewhere)?
 
hi there. Yep, i upgraded to Tiger. That might be it!! I'll check it out and see if I can fix it :)

thanks for the suggestion

Ade
 
I can say that cron still works fine - I have a few custom cron jobs and they're still being run.

Hmm, post up your script, and maybe we can figure out what may be going wrong with it.
 
Hi there. I got a small basic cron to run just writing out to a file, so cron is obviously working but not with my script for some reason (which is weird). Here is the cron entry (this is being run from my account, not via sudo su or anything like that:

58 * * * * /Users/John/backup_setup/run_backup.sh

This is just to try it once an hour

and here is the script:

#!/bin/sh

# This shows an rsync command complete with multiple directories.

WEBSITES_DIR='/websites/'
/usr/bin/rsync -avz --delete --timeout=999 --exclude-from backup_excludes.txt --delete-excluded -e ssh $WEBSITES_DIR john_powerbook@222.222.222.222:websites/


SOURCE_DIRS='/Users/John/'

/usr/bin/rsync -avz --delete --timeout=999 --exclude-from backup_excludes.txt --delete-excluded -e ssh $SOURCE_DIRS john_powerbook@222.222.222.222:backup/

The above script works fine when run from the command line, so its strange that its not working from cron.

ANY help appreciated :)

Thanks

John
 
When there is an error in a cron job, it will mail the output of the error to the user. Since most people change the /etc/crontab file for cron jobs, this means the mail will go to root. However, unless you've specifically changed it, all mail to root is forwarded to /dev/null aka "the black hole" and is gone forever.

If a) you are using /etc/crontab to set up the cron job, and b) you haven't changed the default behavior, you can edit /var/root/.forward and either replace the string /dev/null with the name of your normal user, or you can just delete the file totally.

In the first case, all email going to root would be sent instead to the user name you specify, and in the second case the mail would be sent to root (and you'd need to login as root to read it). The first case is better, IMO.

To read this mail, the easiest way is to use the mail command on the command line.
 
Hi. Could someone give me some help to test if cron is even working now? I've been doing some reading today that with Tiger cron doesn't work any more and that launchd replaces it - can someone give me some advice to see if cron itself is still running? Then I can take another approach if it isn't

Thanks

john
 
cron still runs. But if seeing is the only way to believe for you, you can do this command:

ps -auxc | grep "cron"

If cron is running, it'll show something like this (not exactly this, but very similar)

root 51 0.0 0.1 27512 612 ?? Ss 10:57AM 0:00.03 cron


If it's not running, you won't get any output (or, it may give you grep back. If the command at the end doesn't say cron, then it's not running).
 
Yep, cron seems to be running then (thanks for this):

root 49 0.0 0.1 27512 452 ?? Ss Mon07AM 0:00.74 cron

which brings me back to my original question then :( If cron is still running why has it stopped running my backup shell script? In one of the previous emails it described reading the email error, but it was pointing to /dev/null. What would I point it to for me to read any errors? My username is "John" on this machine, so what path would I put in?
 
Just the name John. Um, the short user name, not the full one - the same as your home folder is named. No path needed, just replace the /dev/null string with John. Then, any email sent to root will be sent to the user John instead.
 
Hi there. Ok, no emails in to "John" - I changed everything here, so no error email, but the script doesn't appear to be being run. Any ideas at all?
 
Back
Top