I'm having a weird problem. I use launchd to run a bunch of shell scripts that update content on my site. It was working fine when it was just calling scripts normally. But now I made the script a little more complicated, and the launchd plist needs to send an argument when it calls the script. No problem, launchd has ProgramArguments
just for that. Problem is, it's just not working. Here is the important part of my launchd.plist:
<key>ProgramArguments</key>
<array>
<string>/scripts/content.php</string>
<string>update</string>
</array>
I've omitted just a Label
key and a StarCalendarInterval
key. As you can see, the path to the script is the first element in the array. That seems to be the most common cause of this problem.
So to be clear, this DOES launch my script. But it does NOT pass any arguments. I had the script output print_r($argv) to an error log and it outputs this:
Array ( [0] => /scripts/content.php )
Most important here, is that if I run the following from the command line, my script runs perfectly and as expected:
./content.php update
It seems like I'm doing everything right, I'm not sure what's going on with this?
Best Answer
If you edit a
.plist
you need to runlaunchctl unload ...
andlaunchctl load ...
, otherwise the system will keep using the previous (cached) version.