Crontab email issue

Hi,

I have a script that sends a db extract file as an email attachment.

I have a crontab created to run it everyday at 8 am..

00 08 * * * ksh /home/rtaaa/tbasd/report.sh > /home/rtaaa/tbasd/logs/report.log

When i just run the "ksh /home/rtaaa/tbasd/report.sh > /home/rtaaa/tbasd/logs/report.log" from the command prompt, the email will be sent out without any issues.. but when its triggered by the crontab, the email is not getting sent.. the whole script is running well except the email part.

This is what i am doing to send the file: "sendmail $ADDR < $MAILFILE"

I have been trying to debug this without success for a while, any help is appreciated.

Thanks.

first

take out the ksh in the crontab and include
#!/bin/ksh
at the top of the script.

second

you can record the errors in your log with 2>&1

so give this a shot:

00 08 * * * /home/rtaaa/tbasd/report.sh >> /home/rtaaa/tbasd/logs/report.log 2>&1

Thanks for helping me find the error..

Now i could trace the error:

but i am getting this error: "sendmail: not found"

Again, I am getting this error only when Its run by the cron. I won't get this when i run it from the command prompt.

thanks,
Rama

Best way to solve this (considering best practices) is specify full path name to sendmail in the script. You can find out where sendmail lives by typing:

which sendmail

(hint: it's probably /usr/lib/sendmail)

How to disable crontab from sending email to user from configuration.?

I mean instead of redirecting > /dev/null 2>&1 at the crontab entry.

Instead of specifying the complete pathname for each program,
you might want to make the script self-sufficient by including PATH and umask settings:

PATH=/bin:/usr/bin:/usr/lib:/usr/local/bin
export PATH
umask 022

Handle all redirection within the script as well. It also helps to create a directory just for cron jobs, so your final script would be something like /usr/local/cron/run-report.