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?
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.)
I was able to find cron-job log in,
Following is a cron job log I got for running an AWS CLI command,
From build@BuildServer1.local Fri Mar 2 10:00:00 2018 Return-Path: <build@BuildServer1.local> X-Original-To: build Delivered-To: build@BuildServer1.local Received: by BuildServer1.local (Postfix, from userid 501) id A7A94296CBA3; Fri, 2 Mar 2018 10:00:00 +0100 (CET) From: build@BuildServer1.local (Cron Daemon) To: build@BuildServer1.local Subject: Cron <build@BuildServer1> /app/scripts/s3-sync.sh X-Cron-Env: <SHELL=/bin/sh> X-Cron-Env: <PATH=/usr/bin:/bin> X-Cron-Env: <LOGNAME=build> X-Cron-Env: <USER=build> X-Cron-Env: <HOME=/Users/build> Message-Id: <20180302090000.A7A94296CBA3@BuildServer1.local> Date: Fri, 2 Mar 2018 10:00:00 +0100 (CET) upload: ../../app/logs/debug.log to s3://**my-s3***/app/logs/debug.log
Turned out when cron is running the job (as me),
/usr/local/bin is not in the
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).