Skip to main content
Question

Unrelated - mail command not working in script


Forum|alt.badge.img+12

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

Forum|alt.badge.img+12
  • Author
  • Contributor
  • 186 replies
  • June 9, 2010

Travis,

Thank you! Your solution did the trick!


  • 0 replies
  • June 9, 2010

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


Forum|alt.badge.img+12
  • Author
  • Contributor
  • 186 replies
  • June 9, 2010

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>


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings