Hello,
I've got a script that check for hard-drive temperature and send an email if one of the hard-driver is too hot. This script run perfectly when running "by hand", but once added to the crontab, it mostly works, but the emails sent are empty while its subject is OK!!! I know that cron environment is not a full user environment but I can't figure where the problem stand (what environment variable I'm missing).
Here's my script:
Code:
#!/bin/sh
check_one () {
hdd="$1"
if [ -z "$2" ]; then
temp_max=55
else
temp_max=$2
fi
temp=`hddtemp "$hdd" | awk -F":" '{print $3}' \
| sed 's/^ *//' | sed 's/[^0-9]*$//'`
if [ "$temp" -gt "$temp_max" ]; then
echo "$hdd reached $temp °C > $temp_max °C\n"
fi
}
if [ -z "$1" ]; then
TEMP_MAX=55
else
TEMP_MAX=$1
fi
if [ ! -z "$2" ]; then
EMAIL=$2
fi
WARNING="`check_one /dev/sda $TEMP_MAX`"
WARNING="$WARNING`check_one /dev/sdb $TEMP_MAX`"
WARNING="$WARNING`check_one /dev/sdc $TEMP_MAX`"
if [ ! -z "$WARNING" ]; then
if [ -z "$EMAIL" ]; then
echo -e "$WARNING"
else
echo -e $WARNING | mailx -s 'Harddrive temperature' $EMAIL
#TMPFILE=`mktemp`
#echo -e $WARNING > "$TMPFILE"
#mailx -s 'Harddrive temperature' $EMAIL < "$TMPFILE"
#rm "$TMPFILE"
fi
fi
My "/etc/ssmtp/ssmtp.conf" should be OK since the emails are received, but maybe something's missing there due to cron?
Code:
root=jf.argentino@email.fr
AuthUser=jf.argentino@email.fr
AuthPass=passwd
UsesTLS=YES
UsesSTARTTLS=YES
mailhub=ssl0.ovh.net:465
"/etc/ssmtp/revaliases" is empty
and by crontab:
Code:
0-59/5 * * * * /usr/bin/hddtemp.sh 55 jf.argentino@email.fr
If I'm storing the message to send into a file (commented in the script above), the email is still empty...
If I do not erase the temporary file, the email is still empty, but the file contents the message I want to send.
If the message content is not in a variable, I'm receiving it...
So it looks like my problem is relative to both variable and redirection handling by cron, but I can't fix this.
Does anybody have an idea?
My system is a Scientific Linux 6.3 up to date