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" [email protected]
and here's my plist file:
<?xml version="1.0" encoding="UTF-8"?> <!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>"com.fer.ip"</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/IPSend.sh</string>
</array>
<key>OnDemand</key>
<false/>
<key>StartInterval</key>
<integer>60</integer>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/test.stdout</string>
<key>StandardErrorPath</key>
<string>/tmp/test.stderr</string>
</dict>
</plist>
Both standard error and standard out files are always empty
grep
three times, just use:ifconfig | awk '/broadcast/{print $2}'