For anyone who ends up on this page, I realized I should post the answer:
Using launchd instead of cron does indeed fix the authorization problem. Your user launchd jobs (which run only when you are logged in) correctly use the SSH agent information that was unlocked via your keychain as part of login (as part of standard OS X key management, no other software required).
To minimize my interactions with launchd, I created a single launchd job that calls a bash script. In this way I can simply edit the script without dealing with launchd.
Here's the launchd file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.mycron.hourly</string>
<key>ProgramArguments</key>
<array>
<string>/Users/john/bin/cron.hourly</string>
</array>
<key>Nice</key>
<integer>1</integer>
<key>StartInterval</key>
<integer>3600</integer> <!-- start every X seconds -->
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
I saved the file to ~/Library/LaunchAgents/com.mycron.hourly.plist
, and then loaded it with:
launchctl load ~/Library/LaunchAgents/com.mycron.hourly.plist
Once loaded, it will run right away and then again every 60 minutes.
If you follow the same procedure, you'll want to change the `ProgramArguments' string with the right path to your script.
As morth pointed out, for the default Mac OS X Apache installation these are located in: /var/log/apache2/error_log
.
The location can be changed in the httpd config using the ErrorLog directive, even for individual virtual hosts. Also note that if you installed another Apache besides the built-in one (like through MacPorts, or MAMP), this probably is different for you too. In that case you should have a look at the httpd.conf or equivalent for your installation.
tip:
If you have Growl installed, also have a look at this 'growltail' script. I think it's great to get notified of errors while developing, without having the need to switch back to the Terminal all the time.
Best Answer
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.)