So the answer was not a big deal, but it might help others to share the solution. I had simply forgotten, as we will when moving around several virtualenvs, which python I was in. If you're having trouble and your .plist
and script seem well-formed, it won't hurt to run which python
etc, and check the result against the path you're listing in your program arguments.
Simple Plist. No output. What gives?
Domanda
I'm trying find exactly what's wrong with a larger job that I'm trying to schedule with launchd for the first time. So I made the simplest python file I could think of, print 'running test'
, titled it com.schedulertest.plist
and then made a plist file like so:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.schedulertest.py.plist</string>
<key>ProgramArguments</key>
<array>
<string>arch</string>
<string>-i386</string>
<string>/usr/bin/python2.7</string>
<string>/Users/user/Documents/Python_Alerts_Project/schedulertest.py</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>60</integer>
</dict>
</plist>
Then I saved it in $HOME/Library/LaunchAgents/
and ran:
launchctl load com.schedulertest.plist
I should be getting the print output from my py script every 60 seconds, right? I don't see anything though -- is there an obvious fault in my script or process?
Soluzione
Altri suggerimenti
Troubleshooting
To debug
.plist
, you can check the log for any error, e.g.tail -f /var/log/system.log
To specify custom log, use:
<key>StandardOutPath</key> <string>/var/log/myjob.log</string> <key>StandardErrorPath</key> <string>/var/log/myjob.log</string>
To find the latest exit status of the job, run:
launchctl list com.schedulertest.plist
To make sure the syntax is correct, use
plutil
command.
See: Debugging launchd
Jobs section of Creating Launch Daemons and Agents page.