Quantcast
Channel: Using launchd to monitor a running program or process - Ask Different
Viewing all articles
Browse latest Browse all 3

Using launchd to monitor a running program or process

$
0
0

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/bashPROC=$1if ! /usr/bin/pgrep $PROC > /dev/nullthen    /bin/echo "$PROC is not running!" | /usr/bin/mail -s "$PROC down" email@mydomainfi

Not much to go wrong there...


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>