1

I have a script that redirect the df output to a file and then send it in an email. The mail command is set up as following:

/usr/bin/mail -s "Subject" -r from@nowhere.com toaddress@somewhere.com < /tmp/diskSpace.txt

Everything is working correctly when I run this script as root user but I have a strange behaviour when I run it from the root crontab. In this case the message is delivered but the content of /tmp/diskSpace.txt is attached to the email instead to be the body. I even tried to replicate the root environment running the cron as:

env `cat root-env-saved-to-this-file` /bin/bash mailscript.sh

but nothing changed. Any suggestion or I should just handle this with perl mail libraries ?

0wn3r
  • 866
  • 1
  • 8
  • 21
  • What version of the mail command are you using? Mine (bsd-mailx) doesn't have -r as an option. – wurtel Sep 22 '14 at 12:42

1 Answers1

0

Try to add this before your cron job.

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

It will show to cron user where executable directories are.

Peycho Dimitrov
  • 1,118
  • 9
  • 10