I've written a simple bash script to check whether a program (supplied as its only argument) is running and send an email to a set address in the script if it's not. The script works if run on the command line, but I cannot for the life of me get it to work under launchd as a user agent (~/Library/LaunchAgents) where I try to set it to run every minute. The latest incarnation of the relevant .plist file is (monitoring Dropbox):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!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>greencollar.Dropbox.checkRun</string>
<key>StartInterval</key>
<integer>60</integer>
<key>Program</key>
<string>/Users/greencollar/Documents/code/proc_check.sh</string>
<key>ProgramArguments</key>
<array>
<string>proc_check.sh</string>
<string>Dropbox</string>
</array>
</dict>
</plist>
Yes - the bash script is executable and no there are no entries in Console indicating any problems with the .plist file. I have tried making /bin/bash the program, but that doesn't seem to make any difference and reading execvp(3) seems to hint that it wouldn't. I've also tried having everything under <ProgramArguments>
without any luck as well. Any help would be greatly appreciated as this seems to me pretty basic and it's very frustrating that I can't get it to work!
----------------------------- 1st Edit ---------------------------
Here is the pared-down basics of the shell script:
#!/bin/bash
PROC=$1
if ! /usr/bin/pgrep $PROC > /dev/null
then
/bin/echo "$PROC is not running!" | /usr/bin/mail -s "$PROC down" email@mydomain
fi
Not much to go wrong there...
proc_check.sh
shell script. Because without it, there cannot be a complete troubleshooting process that's done easily or by trying to replicate as exact as possible, where the issue is..plist
in the question, which I admit I hadn't because I thought I saw a problem with it, and it did trigger (on my system anyway). So, I do not believe that's where the issue is. My new answer I believe may be spot on for where the issue could be. Obviously without seeing the contents of the script I can't say for sure, however this is most likely where the issue may be..plist
and theproc_check.sh
, using my$HOME
and rest of your path of course, and this works when called bylaunchd
for me in testing with "Caculator" andsay $PROC is not running
. I didn't test sending email as my system is not setup to do that. So you might want to test like I did to see if that works and then if it does the troubleshooting will need to be done on howmail
might be being handled when triggered bylaunchd
. BTW I'm running OS X 10.8.5, what version are you running?