This is a memorandum of what to do when a shell script including sendmail on Linux works with terminal commands but does not work with cron.
After writing the shell in the following format, I wrote cron to run it on time. Then, it worked normally on the command and the mail was sent, but the mail was not sent even at the scheduled time written in cron.
mail.sh
#!/bin/sh
{
echo "From: <****@gmail.com> "
echo "To: <****@gmail.com> "
echo "Subject:title"
echo "Content-Type: text/plain;charset='UTF-8'"
echo "Content-Transfer-Encoding: base64"
}| sendmail -i -t
So, I first suspected that there was a problem with cron, changed the file permission to chmod 777, and then checked the log, but cron seemed to work without problems.
$ tail /var/log/cron
Aug 7 14:20:01 ip-***-**-*-** CROND[17995]: (root) CMD (/home/***/mail.sh)
I was able to conclude that the problem was in sendmail, so I looked around and found that if I added / usr / sbin /, it worked fine and the mail was sent, and I was able to receive it in the junk mail folder on gmail.
mail.sh
#!/bin/sh
{
echo "From: <****@gmail.com> "
echo "To: <****@gmail.com> "
echo "Subject:title"
echo "Content-Type: text/plain;charset='UTF-8'"
echo "Content-Transfer-Encoding: base64"
}| /usr/sbin/sendmail -i -t
Recommended Posts