Q: sending mail from launchd
Hi there,
i have a script that checks SMART status and sends an email with results. This script used to work fine under previous versions of OS (through crontab) but seems to not work with launchd.
Script is executed as scheduled, i can see that all commands are executed but not the last one that sends the email.
here's my script:
#!/bin/bash
+current_date=`/bin/date %m%d%y`
+status0=`/usr/sbin/diskutil info disk0 | /usr/bin/grep SMART`+
+status1=`/usr/sbin/diskutil info disk1 | /usr/bin/grep SMART`+
+/bin/echo "SMART status for server:" > /tmp/SMART_today.txt+
+/bin/echo "hdd1 " $status0 >> /tmp/SMART_today.txt+
+/bin/echo "hdd2 " $status1 >> /tmp/SMART_today.txt+
+email_subject="server2 SMART status"+
+/bin/echo $email_subject >> /var/log/system.log+
+/bin/cat /tmp/SMART_today.txt | /usr/bin/mail -s '$email_subject' user@domain.com -r user@domain.com+
exit
While troubleshooting this i was able to narrow it down to the mail command, which for whatever reason is not completed.
Under launchd, this is setup to run as a user daemon running as root. Manually running this script under root account works just fine
Can anybody help with this?
i have a script that checks SMART status and sends an email with results. This script used to work fine under previous versions of OS (through crontab) but seems to not work with launchd.
Script is executed as scheduled, i can see that all commands are executed but not the last one that sends the email.
here's my script:
#!/bin/bash
+current_date=`/bin/date %m%d%y`
+status0=`/usr/sbin/diskutil info disk0 | /usr/bin/grep SMART`+
+status1=`/usr/sbin/diskutil info disk1 | /usr/bin/grep SMART`+
+/bin/echo "SMART status for server:" > /tmp/SMART_today.txt+
+/bin/echo "hdd1 " $status0 >> /tmp/SMART_today.txt+
+/bin/echo "hdd2 " $status1 >> /tmp/SMART_today.txt+
+email_subject="server2 SMART status"+
+/bin/echo $email_subject >> /var/log/system.log+
+/bin/cat /tmp/SMART_today.txt | /usr/bin/mail -s '$email_subject' user@domain.com -r user@domain.com+
exit
While troubleshooting this i was able to narrow it down to the mail command, which for whatever reason is not completed.
Under launchd, this is setup to run as a user daemon running as root. Manually running this script under root account works just fine
Can anybody help with this?
MacBook Pro; 24" iMac, Mac OS X (10.6.2)
Posted on Jul 28, 2010 6:10 AM
by jaydisc,Solvedanswer
Servers Enterprise
When launchd runs a script and the script is done running, launchd kills any processes trigger by the script unknowingly if they've completed or not.
You can add this directive to the launchd job plist and launchd will then not do that.
That's likely the cause. If not, paste your launchd job plist.
You can add this directive to the launchd job plist and launchd will then not do that.
key>AbandonProcessGroup</key>
<true/>That's likely the cause. If not, paste your launchd job plist.
Posted on Jul 28, 2010 7:06 AM