I've written a script and everything is working so well according to my needs:

a=$(df -h /mnt/smb | tail -n +3 | tr -s ' ' | tr '%' ' ' | cut -d ' ' -f 5)
echo $a

if [[ $a -ge 30 ]]; then
    cat /etc/diskspace/text.txt | sendmail test.gmail.com

I want to run this script every minute via Cron, see my crontab:

* * * * * /etc/diskspacae/vpndrive.sh

As you can see, after running this script if drive space is more than 80%, I want to use sendmail to get a notification in my email.

But I haven't got it when I've run this script from Cron, and I've got this error message in /var/spool/mail/root.

ERROR Message: /etc/diskspace/vpndrive.sh line 34 : sendmail: command not found. 

Don't forget that script executed by Cron are ran in an environment with a limited PATH variable. This means that on the console when you test your script, the console shell will find sendmail without problem. But when ran from Cron, sendmail is not found.

Best practise when writing scripts for Cron is to put the full path to access the command you want to run, just to be sure.

Usually, the sendmail binary is install under /usr/sbin, a path which is not part of the directories looked up by Cron by default. So I would advise to :

  1. Look for the place of sendmail binary (locate sendmail or find / -type f -name sendmail) if locate is not installed)
  2. Write down the full path to execute sendmail in your script
  • just type which sendmail to find the location – Martin Konecny Mar 23 '17 at 16:46

Most probably sendmail is not installed.

To install it type sudo apt-get install sendmail in terminal.

For further configuration visit similar question: how to configure sendmail on ubuntu?

  • 1
    sendmail was so widely used at some time that all the MTA packages I know (sendmail obviously! - postfix - ssmtp) install a binary or symlink called sendmail to submit mails from command line and script. – Benoit Jun 17 '14 at 9:30

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.