2

I have a job scheduled by cron running every day, and the job is about compressing a folder using tar; and I found that the standard output of tar keeps getting written into ~/dead.letter everyday. The content that gets written is just the list of the files that got compressed, just like what you'll see on the command line when running tar manually.

Searching dead.letter shows that it's something related to a partial letter that got interrupted before being sent successfully. I do have a shell script running as daemon that monitors something on the machine and sending out email on specific conditions. The daemon is started using the following command:

setsid ~/send_mail_on_certain_event.sh >~/sendmail.log 2>&1 < /dev/null &

This is the only place that I use mail (actually using ssmtp) on the machine, and it's working as I expected (I got the email I wanted). I don't know if it has anything to do with the cron job's output getting written to dead.letter.

  • 1
    If you log in as the user running that cron job, does mail (to that user) work? – derobert Apr 21 '15 at 17:27
1

When a cron job fails, or has output, cron will try to mail it to the user of the mailjob. When the mail is configured for him.
You have a tar command writing information to stdout and nobody is redirecting stdout. You shoud redirect all stdout and stderr of all your crontab jobs to /dev/null (or some logfile when you are interested in the output).
Example

10 0 * * * tar tvf /tmp/tar.tst /home/era >/dev/null 2>&1

A bit silly: asking tar to be verbose with the -v flag and throwing away everything tar writes. But that is for when you want to test something like

10 10 * * * tar tvf /tmp/tar.tst /home/era

Or you can test

* * * * * echo "Hello and Goodbye Era"

and look for mail under your user account

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.