Results 1 to 2 of 2
Hi,
I am trying to execute a script from crontab and having issues with getting the script to send out an email.
This is my cron expression:
1 12 * ...
- 01-25-2012 #1Just Joined!
- Join Date
- Nov 2011
- Posts
- 10
CRONTAB Email issue
Hi,
I am trying to execute a script from crontab and having issues with getting the script to send out an email.
This is my cron expression:
1 12 * * * /home/Testing/Client/TST.sh -l
The TST.sh script executes a bunch of tests scripts and then sends the resulting output to another script, errors.sh. The Errors.sh script parses the output and is supposed to formulate an email message and then send it out.
if i execute the TST.sh script from the commandline the scripts run as expected and sends out the email correctly. It is only when i try to run it as a cron job does the email not work. When the job runs, the scripts seem to run fine only the email ends up in /var/spool/mail/userid - instead of sending the email out. the email that gets sent to this file also contains the incorrect information.
How can i get the errors.sh to send out the email?
Here is the bit of code i use to send out the email in errors.sh after the output from TST.sh has been parsed:
NOTE: email(at)address.com is an actually email address it wont let me use the 'at' symbol.Code:# script to send simple email # Email To ? EMAIL="email(at)address.com" # Email text/message EMAILMESSAGE="/tmp/emailmessage.txt" echo "Test script completed at: $DATE" > $EMAILMESSAGE echo " $header " >> $EMAILMESSAGE echo " $results " >>$EMAILMESSAGE # send an email using /bin/mail /bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
Last edited by dbo3587; 01-25-2012 at 07:55 PM.
- 01-25-2012 #2Just Joined!
- Join Date
- Jan 2012
- Location
- Rowlett, TX
- Posts
- 4
Instead of using /bin/mail to mail out the results, let cron send them to you. All output (stdout and stderr) produced by the script will be emailed to you.
All you have to do is set the MAILTO variable in your crontab.
Update your script to something like:
Set the MAILTO variable in your crontab:Code:# script to send simple email # Email To ? EMAIL="email(at)address.com" # Email text/message EMAILMESSAGE="/tmp/emailmessage.txt" echo "Test script completed at: $DATE" > $EMAILMESSAGE echo " $header " >> $EMAILMESSAGE echo " $results " >>$EMAILMESSAGE # send everything to stdout cat $EMAILMESSAGE
The next time cron runs, the contents of "/tmp/emailmessage.txt" will be mailed to the address set in MAILTO.Code:MAILTO=penguin@linux.com
Hope this helps.


Reply With Quote