Trying to use launchd to make my iMac running 10.7.5 to email me it´s IP address not working This is the first time I use launchd so there´s a lot I don´t know.

A little bit of background info.

I set up everyting to be able to use the mail command to send emails with my gmail. Wrote a bash script (IPSend.sh) using ifconfig, grep, and mail. Running the script manually as any user including root works perfectly and sends the email to the specified email address. Copied the script to /usr/local/bin/ the directories have rwxr-xr-x permissions and the script -rwxr-xr-x@ everything is root:wheel. Created a plist file and copied it to /Library/LaunchDaemons (-rw-r--r--@  1 root  wheel   918 Dec 25 16:01 com.fer.ip.plist), debugged it with plutil -lint until result was OK.

When I launchctl load /Library/LaunchDaemon/com.fer.ip.plist (as root) I don´t get any errors the email is not sent and the log shows something like:


  Dec 25 16:18:00 dbe4b6a01 com.apple.launchd[1] ("com.fer.ip"): Throttling respawn: Will start in 6 seconds
  Dec 25 16:18:06 dbe4b6a01 com.apple.launchd[1] ("com.fer.ip"): Throttling respawn: Will start in 10 seconds
  Dec 25 16:18:37: --- last message repeated 2 times ---
  Dec 25 16:18:37 dbe4b6a01 com.apple.launchd[1] ("com.fer.ip"): Throttling respawn: Will start in 10 seconds
  Dec 25 16:18:37 dbe4b6a01 com.apple.launchd[1] (0x7f9170659600.anonymous.sendmail[20303]): Failed to add kevent for PID 20303. Will unload at MIG return
  Dec 25 16:18:37 dbe4b6a01 com.apple.launchd[1] (0x7f9170659600.anonymous.sendmail[20303]): Unloading PID 20303 at MIG return.
  Dec 25 16:18:47 dbe4b6a01 com.apple.launchd[1] ("com.fer.ip"): Throttling respawn: Will start in 10 seconds
  Dec 25 16:19:00: --- last message repeated 1 time ---
  Dec 25 16:19:00 dbe4b6a01 com.apple.launchd[1] ("com.fer.ip"): Throttling respawn: Will start in 7 seconds


The reason I say "something like this" is that somtimes I dont get the "Failed to add kevent for PID" or it appears earlier.

I'm totally lost. No idea what the "Failed to add kevent for PID" means or why it is not working as a launchd process when it works manually. Please help!

Here's my script changing my email address:

#!/bin/sh

ifconfig | grep -o -E [0-9]+[.][0-9]+[.][0-9]+[.][0-9]+ |grep -v "127" |grep -v "255" | mail -s "iMac" myemail@isp.com.xx


and here's my plist file:

&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; 

&lt;dict&gt;
        &lt;key&gt;label&lt;/key&gt;
        &lt;string&gt;"com.fer.ip"&lt;/string&gt;

        &lt;key&gt;ProgramArguments&lt;/key&gt;

        &lt;array&gt; 
            &lt;string&gt;/usr/local/bin/IPSend.sh&lt;/string&gt;
        &lt;/array&gt;

        &lt;key&gt;OnDemand&lt;/key&gt;
        &lt;false/&gt;

        &lt;key&gt;StartInterval&lt;/key&gt;
        &lt;integer&gt;60&lt;/integer&gt;

        &lt;key&gt;KeepAlive&lt;/key&gt;
                &lt;true/&gt;

        &lt;key&gt;StandardOutPath&lt;/key&gt;
        &lt;string&gt;/tmp/test.stdout&lt;/string&gt;

        &lt;key&gt;StandardErrorPath&lt;/key&gt;
        &lt;string&gt;/tmp/test.stderr&lt;/string&gt;

&lt;/dict&gt;
&lt;/plist&gt;


Both standard error and standard out files are always empty
I don't know why I missed these the first time, but upon reviewing your problem just now, I noticed a few inconsistencies in the plist file which might well be the problem.  I think this will fix your problem.

    &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; 
&lt;plist version="1.0"&gt;
                    &lt;dict&gt;
                            &lt;key&gt;Label&lt;/key&gt;
                                &lt;string&gt;com.fer.ip&lt;/string&gt;
                            &lt;key&gt;Program&lt;/key&gt;
                                &lt;string&gt;/usr/local/bin/IPSend.sh&lt;/string&gt;
                            &lt;key&gt;RunAtLoad&lt;/key&gt;
                                &lt;true/&gt;
                            &lt;key&gt;KeepAlive&lt;/key&gt;
                                &lt;false/&gt;    
                   &lt;/dict&gt; 
&lt;/plist&gt;


Hope that this helps!

F.