Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jasnw

macrumors 65816
Original poster
Nov 15, 2013
1,058
1,139
Seattle Area (NOT! Microsoft)
I've had a long-used, annually run, cron job just fail and I'm trying to figure out why. The script (tcsh) uses the diskutil mount command to mount an external drive by it's device ID (disk7s1 in this case). This used to run fine, but now it fails when run as a cron job. If I run the same script from Terminal it runs fine. It sounds like another "Full Disk Access" problem, but cron is already in the list. Does diskutil, a system utility, also need to be listed? I tried listing the script but that didn't help. I've attached the output from 'diskutil list' for this drive.
diskList.png
 
I found the solution, but I don't understand what's going on. Turns out the reason this failed is because the script could not find diskutil, which lives in /usr/sbin. If I invoke '/usr/sbin/diskutil' instead of just 'diskutil' everything runs fine from cron.

Directory /usr/sbin is in both path (and PATH) when the script is run in Terminal, but not when run from cron (I run in the tcsh shell in Terminal, and set SHELL to /bin/tcsh in my crontab file). Now, the path is supposed to be what's in /etc/paths and any files found in /etc/paths.d. My /etc/paths file contains six directory names including /usr/sbin. Only two of the six (/usr/bin and /bin) show up in the path variable when the script is run via cron, but all six show up when run in Terminal. And none of the directories listed in the files in /etc/paths.d are added to path when running from cron.

So, I have a fix, but i don't know why it was needed. What's going on with the construction of the path variable? More digging needed.
 
OK, mea culpa, I should have understood this from the get-go. The underlying issue is that the cron environment is bare bones, and something within the cron setup limits what ends up in the path/PATH variables regardless of what's set up for shell environments. The two solutions are the one mentioned earlier or putting a PATH variable specification in your crontab file. I've now done this, adding the paths that I really want cron to have access to. Merry Christmas.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.