I have created the following linux script:
#!/bin/sh
tempfront=27
tempreartop=60
temprearbottom=65
if [ "$tempfront" -gt 26 ] || [ "$tempreartop" -gt 70 ] || [ "$temprearbottom" -gt 70 ]; then
echo "To: [email protected]
From: [email protected]
Subject: Test Alert
ALERT
Front temp: $tempfront oC
Back temp up: $tempreartop oC
Back temp down: $temprearbottom oC" > /home/odroid/alerts.txt
ssmtp [email protected] < /home/odroid/alerts.txt
fi
I execute this script manually and works fine, it sends the email alert to [email protected]. Here's what gmail sends out:
Return-Path: <[email protected]>
Received: from [email protected]
(ppp046177171064.abcs.fe. [xx.xx.xx.xx])
by mx.google.com with ESMTPSA id k2sm8590878wix.4.2015.04.26.12.54.57
for <[email protected]>
(version=TLSv1 cipher=RC4-SHA bits=128/128);
Sun, 26 Apr 2015 12:54:59 -0700 (PDT)
Message-ID: <[email protected]>
Received: by [email protected] (sSMTP sendmail emulation); Sun, 26 Apr 2015 22:54:56 +0300
Date: Sun, 26 Apr 2015 22:54:56 +0300
To: [email protected]
From: [email protected]
Subject: Test Alert
ALERT
Front temp: 27 oC
Back temp up: 60 oC
Back temp down: 65 oC
But when I set it to run in a cron job, the email comes corrupted like this:
.....
From: root <[email protected]>
X-Google-Original-From: root (Cron Daemon)
Received: by [email protected] (sSMTP sendmail emulation); Sun, 26 Apr 2015 23:00:01 +0300
Date: Sun, 26 Apr 2015 23:00:01 +0300
To: root
Subject: Cron <root@odroid> /home/odroid/testalert.sh >/dev/null
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
/home/odroid/testalert.sh: 19: /home/odroid/testalert.sh: ssmtp: not found
And also it is not being received by [email protected]. Can someone explain this? Why cron is messing things up?
Update: I noticed that some other cron jobs are output to email as well!
...
Date: Mon, 27 Apr 2015 06:30:01 +0300
From: Cron Daemon <[email protected]>
To: root
Subject: Cron <root@odroid> /home/odroid/motion_day.sh >/dev/null
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
[0] Processing thread 0 - config file /etc/motion/motion.conf
[0] Motion 3.2.12 Started
[0] Motion going to daemon mode
This is just a script for webcam monitoring, nothing to do with email! The cron entry for that is
30 6 * * * /home/odroid/motion_day.sh >/dev/null