This on an iMac running Big Sur. (I asked over at AskDifferent, but no one knew the answer.)
This script is set up to run by launchd once a day to get battery data from a NUT (Network UPS Tools) Server running on a Raspberry Pi:
#!/bin/bash
# Shell script to query upsmon regarding ups battery status
log=/Users/mnewman/ups/ups.log
email="[email protected]"
echo `date` "UPS Check">> $log
# get UPS data from Raspsky
bat=`/usr/local/bin/upsc apcups@raspsky | \
grep -E 'battery.charge:|input.voltage:'`
# write USB data to the log
echo $bat >> $log
# send an email
echo "$bat" | /usr/bin/mail -s "UPS Status" $email
exit 0
The script runs fine from the command line. It runs from launchd except for the email line which fails silently - nothing in the console log and nothing in stderr. The email just doesn't get sent.
However, if I run the mail command in verbose mode:
echo "$bat" | /usr/bin/mail -v -s "UPS Status" $email
it runs fine.
Or, if I add another command after the email line:
curl -sS https://api.prowlapp.com/publicapi/add \
-F apikey=$apikey -F application=$(hostname) -F event="UPS" \
-F description="$bat"
it runs fine.
Can anyone explain what's doing on here?
/usr/bin/mail -s"UPS" "$email"