Unrelated - mail command not working in script

Kedgar
Contributor

Hello,

I have an rsync backup script that creates log files when it runs. Those log files are then sent to my team using the mail command. This works perfectly when run manually, but when run as a Launch Daemon, the mail piece doesn't work.

I know there are probably differences in the non-interactive root shell, but does anyone have a suggestion to get this working? Below is the command as in my script:

/usr/bin/mail -s "Server $logfile" account at domain.com < $logfile;

Thanks for your help,
Ken

3 REPLIES 3

Kedgar
Contributor

Travis,

Thank you! Your solution did the trick!

Not applicable

In your Launch Daemon plist, include this key:

<key>AbandonProcessGroup</key>
<true/>

What may be happenning is a child process is created to send the email,
but then your script completes, and by default, launchd will kill that
child process before it is actually able to send the email. This change
worked for us.

Here's Apple's documentation on it:

http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPa
ges/man5/launchd.plist.5.html

Travis

Kedgar
Contributor

Thanks Travis, I'll give itake a look. I also added this environment variable below in my launch daemon. I noticed it shows when you do a printenv as root, but if you run printenv through a launch daemon, there is not much declared. I also attempted to add the default environment paths, but that didn't do anything. We'll see where this gets me.

<key>EnvironmentVariables</key> <dict> <key>MAIL</key> <string>/var/mail/root</string>
</dict>