i have cronjob runs .sh script should make .txt file , send email.
i use sudo crontab -e
here script:
send_update.sh, -rwxrwxrwx
#!/bin/sh python /home/myusername/backend/mypy.py > update.txt sed -i '1s/^/subject: daily update /' update.txt sendmail myemail@gmail.com < /home/myusername/backend/update.txt echo "tester" >> tesert.txt
interestingly, file run in echo print file not recieve email.
if run file command line typing sudo ./send_update.sh
send email.
edit 1
the cron file line looks like:
* * * * * cd /home/myusername/backend && ./send_update.sh
edit 2
tesert.txt in same folder send_update.sh , printed cron job
edit 3
all files involved have permissions: -rwxrwxrwx
edit 4
#!/bin/sh python py2db.py > update.txt sed -i '1s/^/subject: daily update /' update.txt sed -i '$ d' update.txt date >> update.txt sendmail myemail@gmail.com < update.txt
this new send_update.sh file. prints recent minute update.txt every minute, never sends email.
edit 5
as suggested changed file
#!/bin/sh python py2db.py > update.txt || echo "error python" >>/tmp/error.log sed -i '1s/^/subject: daily update /' update.txt || echo "error sed1" >>/tmp/error.log sed -i '$ d' update.txt || echo "error sed2" >>/tmp/error.log date >> update.txt || echo "error date" >>/tmp/error.log sendmail myemail@gmail.com < update.txt || echo "error sendmail" >>/tmp/error.log
and after runs cat /tmp/error.log
reads error sendmail
edit 6
after looking through logs have found:
sendmail: not found
i trying update path include sendmail. if can direct me on how appreciated.
edit 7
changing sendmail
/usr/sbin/sendmail
fixed issue , suggested error checking led me there.
add debug script , log errors in file, example :
#!/bin/sh python py2db.py > update.txt || echo "error python" >>/tmp/error.log sed -i '1s/^/subject: daily update /' update.txt || echo "error sed1" >>/tmp/error.log sed -i '$ d' update.txt || echo "error sed2" >>/tmp/error.log date >> update.txt || echo "error date" >>/tmp/error.log sendmail myemail@gmail.com < update.txt || echo "error sendmail" >>/tmp/error.log
maybe don't have path 1 of command, try export path= too.
Comments
Post a Comment