I have an issue with a script, which works fine except that it only sends email when I run it directly from the shell but when called during crontab it doesn't send the emails.There are 2 scripts the main script which does a backup and it calls another script which sends the email. the backup script dump the summary of the operation in a file and reads the file again when to pass it to the email sender script to send. Based on how ssmtp works that's the architecture I have come up with.  I needed to change the subject based on the success or failure of the operation. I have been using my gmail thus using the ssmtp library to send the email. How to make the backup script send the email when called by crontab schedule?#!/bin/bash# File system Parameters#=========================================================================TIMESTAMP=`date +%F-%H.%M.%S`TODAYS_DATE=`date +%Y-%m-%d`BACKUP_PATH=/mnt/backups/mongoSCRIPT_PATH=/root/scriptFILE_NAME=mongodb-$TIMESTAMP# Email Parameters#=========================================================================TEMPLATE_FILE=/tmp/template.txtEMAIL_SUBJECT_CONTEXT=XyloEMAIL_RECIPIENT=myeamilEMAIL_SENDER=DB man#=========================================================================BACKUP_PATH=$BACKUP_PATH/$TODAYS_DATEecho; echo files will be geneated in  $BACKUP_PATH | tee $TEMPLATE_FILE#=========================================================================[ ! -d  $BACKUP_PATH ] && mkdir -p $BACKUP_PATH || : if [ -d $BACKUP_PATH ]; then    cd $BACKUP_PATH    TMP_BACKUP_DIR=$BACKUP_PATH/mongodb-$TIMESTAMP    echo; echo => $(date +%F-%H.%M.%S) Backing up Mongo Server: $MONGO_HOST:$MONGO_PORT | tee -a $TEMPLATE_FILE; echo -n ' ' ;    if [ $MONGOUSERNAME !=  -a $MONGOPASSWORD !=  ]; then        $MONGODUMP_PATH --host $MONGO_HOST:$MONGO_PORT -u $MONGOUSERNAME -p $MONGOPASSWORD --out $TMP_BACKUP_DIR >> /dev/null    else         $MONGODUMP_PATH --host $MONGO_HOST:$MONGO_PORT --out $TMP_BACKUP_DIR >> /dev/null    fi    echo; echo => $(date +%F-%H.%M.%S) Mongo Server: $MONGO_HOST:$MONGO_PORT  backup files generated  | tee -a $TEMPLATE_FILE; echo -n ' ';    if [ -d $TMP_BACKUP_DIR ]; then        if [ $FILE_NAME ==  ]; then            FILE_NAME = mongodb-$TIMESTAMP        fi        echo; echo => $(date +%F-%H.%M.%S) dumping file into  $FILE_NAME.tar.gz  | tee -a $TEMPLATE_FILE; echo -n ' ';        $TAR_BIN_PATH --remove-files -czf $FILE_NAME.tar.gz $TMP_BACKUP_DIR >> /dev/null        if [ -f $FILE_NAME.tar.gz ]; then            echo => $(date +%F-%H.%M.%S) successfully generated file $FILE_NAME.tar.gz of size: `du -sh $FILE_NAME.tar.gz`  | tee -a $TEMPLATE_FILE; echo;            echo; echo => $(date +%F-%H.%M.%S) Uploading $FILE_NAME.tar.gz to $S3_BUCKET_NAME on s3 | tee -a $TEMPLATE_FILE; echo -n ' ';                s3cmd put $FILE_NAME.tar.gz s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/$FILE_NAME.tar.gz                filename=s3://$S3_BUCKET_NAME/$S3_BUCKET_PATH/$FILE_NAME.tar.gz        count=$(s3cmd ls ${filename} | awk \$4 == \${filename}\ { print \$4 } | wc -l)#            if [[ $? -eq 0 ]]; then         if [ $count -eq 0 ]; then                echo !!!!=> File $FILE_NAME.tar.gz could not be added to s3 | tee -a $TEMPLATE_FILE                /bin/sh $SCRIPT_PATH/s3_backup_email_sender.sh $EMAIL_RECIPIENT $EMAIL_SENDER $EMAIL_SUBJECT_CONTEXT BACKUP FAILURE [s3 Upload] $(cat $TEMPLATE_FILE)            else               echo => $(date +%F-%H.%M.%S) File $FILE_NAME.tar.gz has successfully be added to s3 | tee -a $TEMPLATE_FILE                           /bin/sh $SCRIPT_PATH/s3_backup_email_sender.sh $EMAIL_RECIPIENT $EMAIL_SENDER $EMAIL_SUBJECT_CONTEXT BACKUP SUCCESSFUL $(cat $TEMPLATE_FILE)            fi            if [ -d $TMP_BACKUP_DIR ]; then                    rm -rf $TMP_BACKUP_DIR            fi         else            echo !!!=> Failed to create backup file: $BACKUP_PATH/$FILE_NAME.tar.gz  | tee -a $TEMPLATE_FILE; echo;            /bin/sh $SCRIPT_PATH/s3_backup_email_sender.sh $EMAIL_RECIPIENT $EMAIL_SENDER $EMAIL_SUBJECT_CONTEXT BACKUP FAILURE [Failed to gzip $FILE_NAME.tar.gz] $(cat $TEMPLATE_FILE)        fi    else        echo; echo !!!=> Failed to backup mongoDB or Nothing to Back up  | tee -a $TEMPLATE_FILE; echo;         /bin/sh $SCRIPT_PATH/s3_backup_email_sender.sh $EMAIL_RECIPIENT  $EMAIL_SENDER  $EMAIL_SUBJECT_CONTEXT BACKUP FAILURE [Nothing to back up]  $(cat $TEMPLATE_FILE)    fi else     echo !!!=> Failed to create backup path: $BACKUP_PATH | tee -a $TEMPLATE_FILE     /bin/sh $SCRIPT_PATH/s3_backup_email_sender.sh $EMAIL_RECIPIENT $EMAIL_SENDER $EMAIL_SUBJECT_CONTEXT BACKUP FAILURE [Failed to create backup folder] $(cat $TEMPLATE_FILE) fithis is the sending  script#!/bin/bashNow=$(date +%Y-%m-%d)SSMTP=$(which ssmtp)TEMPLATE=/tmp/s3_backup_mail.txtecho To: $1 > $TEMPLATEecho From: $2 >> $TEMPLATEecho Subject: $3 >> $TEMPLATEecho   >> $TEMPLATEecho  $4 >> $TEMPLATE$SSMTP $1 < $TEMPLATE#rm $TEMPLATE
Calling an email script from another script using ssmtp on ubuntu
ubuntu;shell script;email;ssmtp