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.
I had this same problem and found that I could get it to work if the cron job was launched under root.
This Apple discussion link has this note:
[...] Basically, Apple is tracking where an application launches from,
and seems to be preventing processes that launch from "cron" (one of
the system schedulers), even indirectly, from mounting local disk
volumes, even when that application is signed.
Best Answer
You don't need to call
cron
directly. Any commands you want to run need to be added to thecrontab
of the user they should run as. You can edit yourcrontab
by runningor, if you are an admin user and want to edit the
crontab
of another user,PS: Run
man 5 crontab
for details about the format of the file, what kind of special commands you can use, and some samples.5 * * * * /path/to/script
seems to be ok though.