1
I'm using centos 7.0/6.5. The content of /etc/cron.hourly/mail.cron
#!/bin/sh
log=/var/log/mail.cron.log
echo "`hostname` `date`" >> $log 2>&1
mailx -s "test mail" me@example.com < $log
The result of /var/log/mail.cron.log
myhost Mon Jul 28 11:01:01 CST 2014
But, I got a empty e-mail, with correct subject. So, I test this cron manually. I got the correct e-mail content.
myhost Mon Jul 28 11:01:01 CST 2014
myhost Mon Jul 28 11:30:29 CST 2014
Here is the related log /var/log/cron
Jul 28 11:01:01 myhost run-parts(/etc/cron.hourly)[24577]: starting mail.cron
Jul 28 11:01:02 myhost run-parts(/etc/cron.hourly)[24605]: finished mail.cron
I'm wonder how to debug this problem.
What is the output of
crontab -l
?. Also, try changingecho "\
hostname` `date`" >> $log 2>&1to
echo "$(hostname date)" >> $log`. – jimm-cl – 2014-07-28T04:50:28.197@jim, 1. We don't require
crontab -l
to check cron. I'm sure the cron job works, I got the e-mail. The problem is the email's content is empty, it should contains the log. I don't require change to$(hostname date)
, that is not the problem. – Daniel YC Lin – 2014-07-28T06:22:46.300