Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I want to troubleshoot a cron job that worked fine until a recent modification, but I can't find the cron log file, where is it?

share|improve this question
1  
Is it really a cron job or are you using launchd. Cron has been deprecated on OS X. –  jaberg Jan 31 '12 at 17:29
1  
Did you set a log file for the cron job? –  daviesgeek Jan 31 '12 at 17:32
    
it is actually a cron job I set it up with cron -e and I can see it with cron -l and I am sure it worked on Lion and before that on Snow leopard for a long time. –  Ali Jan 31 '12 at 17:54
    
and no, I don't manually set a log file for 'cron' itself, although I write to a log file inside the job and it has stopped working recently after I changed something. –  Ali Jan 31 '12 at 17:55
1  
Ali, Since you have the answer, please post it as an answer and accept it. Do not edit it into the question. You are not only allowed, but encouraged, to answer your own question. –  Jason Salaz Feb 1 '12 at 17:12

3 Answers 3

By default, cron does not log output of executed jobs. It is possible to log the fact that cronjobs have been executed, but that is not the default on OS X either.

In order to investigate cronjob execution output, I suggest modifying your cronjob line to redirect STDOUT and STDERR to logfiles. In your crontab file or after running crontab -e, however you go about it, add something like the following to your job line:

0 0 * * * yourcommand >/tmp/stdout.log 2>/tmp/stderr.log

Doing this should send STDOUT (normally printed or echo'ed output to STDOUT) to a text file named stdout.log in the /tmp directory, and STDERR to stderr.log in the temp directory. Many utilities use STDERR to print special error messages out when they're application errors, and not errors generated by the program's actual execution. (You can read more about STDERR on Wikipedia.)

share|improve this answer
    
Thanks, that's exactly what I have been trying to do, it looks like that cron for some reason fails to run the job in the first place. if I run the job myself by typing the command in the terminal it runs and outputs to the logfile but if I wait for the cron to run it nothing happens, at least no change in the log file, I was thinking maybe a "cron log file" or there was any traces in the consol it could help me find out what is going on, recently I changed my shell from bash to zsh but I don't think that could have affected this either. –  Ali Jan 31 '12 at 18:16
1  
According to erikslab.com/2011/02/04/logging-with-launchd, you could modify the cron plist (/System/Library/LaunchDaemons/com.vix.cron.plist) with a Stdout/Stderr path to debug cron itself. I don't recall if launchctl unloading and launchctl loading the plist is sufficient, or since it's a system daemon if you'd have to restart entirely. I'd suggest the latter just to be sure. –  Jason Salaz Jan 31 '12 at 18:28

Turned out when cron is running the job (as me), /usr/local/bin is not in the PATH.
I found this by trial and error and building the job from scratch from a simple things that I knew would work and gradually added things until I found the problem.

About the other suggestions and answers:
For some reason (at least on my machine, which is running a Lion upgraded from SnowLeopard) cron does not use the parameters specified in the plist files that launchd is sopposed to read /System/Library/LaunchDaemons/com.vix.cron.plist or maybe cron on Lion does not write anything to stdout or stderr.

By the way I am using http://s3tools.org/s3cmd to sync a folder with an Amazon S3 bucket as a backup (like a primitive DropBox).

share|improve this answer

Much easier to simply add the following to /etc/syslog.conf :

cron.* /var/log/cron.log 

Then restart syslog

sudo launchctl unload /System/Library/LaunchDaemons/com.apple.syslogd.plist 
sudo launchctl load /System/Library/LaunchDaemons/com.apple.syslogd.plist 

Tested and working on OSX 10.7.4

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.