I'm trying to send email out from crontab. I've tried making crontab run a basic shell script, as well as specifying the actual command within the crontab. I've tried doing this with mpack and ssmtp . I've noticed that if i execute the command or shell script in a terminal, it works fine. It only fails when i try to schedule it.
This is the basic essence of the command i need to run, where im emailing email@example.com the contents of a file. The file is generated daily and is named after the year, month, and day.
echo -e "to: firstname.lastname@example.org\nsubject: abc123\n" | ssmtp email@example.com < `date +%y%m%d`.txt
Similar thing with mpack
mpack -s "abc123" `date +%y%m%d`.txt firstname.lastname@example.org
I've figured that it has something to do with the date variable. If i substitute that with the actual name of the file, then it all works fine. I've made sure to escape the % symbol, and have tried replacing the backtick with $(date +%y%m%d) with no luck.
Crontab looks like this
10 10 * * * /home/user/./script.sh
Also tried this method
10 10 * * * echo -e "to: email@example.com\nsubject: abc123\n" | ssmtp firstname.lastname@example.org < `date +\%y\%m\%d`.txt
I've made sure that the shell script includes #!/bin/sh, checked all file permissions, and changed the environmental path to include the directories for ssmtp and mpack.
Any suggestions why the date variable is making this fail? Do i need to escape anything else?