1

I have a shell script which sends email when the disk is more than 80% full; when I run the script as sh -x script.sh or ./script.sh I get an email but when I keep the script in cronjob I do not get any email.

The script has execute permissions (755).

When I type mail I can see the cronjob has ran at that time, but there is no email sent.

dr_
  • 29,602
YRVK
  • 63
  • HINT: Set the PATH variable explicitly in your script and make sure it is exported. – mdpc Aug 05 '15 at 06:02
  • @mdpc , I am new to linux, shell scripting. Do I need to add the line export PATH=$PATH:/path/to/dir1 where /path/to/dir is the script.sh path ? – YRVK Aug 05 '15 at 06:15
  • When I run $PATH in my server I can see some values already set, If I add this PATH variable in my script (which points to my script.sh path) will it overwrite the previous values ? – YRVK Aug 05 '15 at 06:20
  • @mdpc I moved the shell script to one of the directories as listed in the $PATH, now the script runs fine from crontab, thank you for the hint – YRVK Aug 05 '15 at 06:52
  • @YRVK. Please Choose "Answer my own Question" below your name, as this is a duplicate and I'm voting as such – eyoung100 Aug 06 '15 at 03:50

1 Answers1

0

You can do 2 things.

  1. Put the full path in for sendmail. /usr/sbin/sendmail for example.
  2. Put the following commands at the beginning of you crontab:

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

Marco
  • 893