Did you remove the PATH
variable at the top of your crontab? If that's missing, it would explain why your script cannot find sendmail
. A typical crontab has the following variables defined. I've added the line for your script as well.
# Global variables
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
* * * * * /bin/sh /home/weed/Desktop/test.sh
The MAILTO
at the top of your crontab is typically used for cron to know where to mail things to. Keep individual configuration in your script.
Also, you're going to need the absolute path for the file you wish to send when running the script via cron. It seems like when you run it manually, you're in the directory you want it to execute in.
You're also using both a pipe to send the output of echo
into sendmail
as well as directing information into standard-in. Remove the standard-in direction and just put all the information you want sent on the left side of the pipe:
log="/var/log/snort/alert/output.txt"
email="vodeni1953@heroulo.com"
cat $log | sendmail $email
If you want to add something to the file you're sending, use the following:
echo -e "Some Header\n\n$(cat $log)" | sendmail $email