OSX Cron causing the following error: Could not setup Mach task special port 9: (os/kern) no access

mac-osxmac-osx-server

Any ideas how to resolve the error that shows up in the Mac OSX system.log file? Or even what the error means?

I have the following cron job that runs every minute:

* * * * * cd /Library/[...]/report/ && nice -n 15 /usr/local/php5/bin/php -f report_generator.php > /dev/null 2>&1

Searches around the internet mentioning commenting out the cron job, but in my cause I can't do this. Most of Google's search results also don't have conclusive mention of what the error actually means.

The full error is:

Jul  2 14:50:00 xserve2 com.apple.launchd[1] (0x10c3f0.cron[46328]): Could not setup Mach task special port 9: (os/kern) no access

Mac OSX 10.5

Best Answer

I'm aware this won't quite fix the original issue but hopefully will tell us if the issue is a bug in launchd or something else.

Have you tried removing the cron job and re-instituting it as a proper launchd job instead? launchd is supposed to run the cron jobs but it sounds like you may be running into a bug.

You can create a launchd job using a GUI such as Lingon if you'd prefer instead of making the .plist yourself.

Sample .plist:

<?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>test.dood.123</string>
    <key>ProgramArguments</key>
    <array>
        <string>cd</string>
        <string>/Library/REMOVED/DIRS/report/</string>
        <string>&amp;&amp;</string>
        <string>nice</string>
        <string>-n</string>
        <string>15</string>
        <string>/usr/local/php5/bin/php</string>
        <string>-f</string>
        <string>report_generator.php</string>
        <string>&gt;</string>
        <string>/dev/null</string>
        <string>2&gt;&amp;1</string>
    </array>
    <key>StartInterval</key>
    <integer>60</integer>
</dict>
</plist>

From my Googling it sounds like it's a bug in launchd running cron jobs. Source: 1

StartInterval will simply run it that many seconds from when the job was last run. StartCalendarInterval will allow you to run it at set times and instead of the <key>StartInterval</key> in the sample above use the following:

Run only at 3:15 AM

 <key>StartCalendarInterval</key>
 <dict>  
     <key>Hour</key>
     <integer>3</integer>
     <key>Minute</key>
     <integer>15</integer>
</dict>

Run every 5 minutes - StartCalendarInterval with an array. (I don't know of a better way to write this out so I'd love someone to elaborate on this)

 <key>StartCalendarInterval</key>
 <array>
     <dict>
         <key>Minute</key>
         <integer>0</integer>
     </dict>
     <dict>
         <key>Minute</key>
         <integer>5</integer>
     </dict>
     <dict>
         <key>Minute</key>
         <integer>10</integer>
     </dict>
     <dict>
         <key>Minute</key>
         <integer>15</integer>
     </dict>
     <dict>
         <key>Minute</key>
         <integer>20</integer>
     </dict>
     <dict>
         <key>Minute</key>
         <integer>25</integer>
     </dict>
     <dict>
         <key>Minute</key>
         <integer>30</integer>
     </dict>
     <dict>
         <key>Minute</key>
         <integer>35</integer>
     </dict>
     <dict>
         <key>Minute</key>
         <integer>40</integer>
     </dict>
     <dict>
         <key>Minute</key>
         <integer>45</integer>
     </dict>
     <dict>
         <key>Minute</key>
         <integer>50</integer>
     </dict>
     <dict>
         <key>Minute</key>
         <integer>55</integer>
     </dict>
 </array>

For more check out the Migrating from cron section on the documentation for launchd and man page