Article 6HZE7 Can not send email from cron

Can not send email from cron

by
mackowiakp
from LinuxQuestions.org on (#6HZE7)
I have such bash script in Debian:

Code:#!/bin/bash
#
[ ! -d ~/tmp ] && mkdir ~/tmp
for i in user1 user2 user3 user4
do
echo $i
/bin/echo "subject: Test mail" > ~/tmp/mail.txt
/bin/echo "from: my_user@gmail.com" >> ~/tmp/mail.txt
/bin/echo "to: $i@gmail.com" >> ~/tmp/mail.txt
/bin/echo >> ~/tmp/mail.txt
/bin/echo "Mail to $i@gmail.com" >> ~/tmp/mail.txt
/bin/echo >> ~/tmp/mail.txt
/bin/cat ~/tmp/mail.txt | sendmail -t #>/dev/null 2>/dev/null
doneInstalled msmtp, msmtp-mta and my_user@gmail.com credentials/parameters defined in /etc/msmtprc.
Script works properly when run from console as root.

But when I put the call to this script in crontab for root - it doesn't execute.
Other cron entries for root execute correctly.
So where am I going wrong?
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments