1

I have a shell script which calls a bash script within it. when I run this shell script manually it works fine however when I schedule this thru cronjob, the bash script is not doing the intended job.

shell script is as follows:

#!/usr/bin/sh

SHDIR=/oracle/CMC/scripts/utils/SCTempConst

export ORACLE_SID ORACLE_HOME SHDIR TIMESTMP DATESTAMP

cd $SHDIR

TO=<actual email address>
BCC=<actual email address>

if [ -f /oracle/CMC/scripts/utils/SCTempConst/SCTempConst.xlsx ]
then
SUBJECT="Subject ...."

ATTCH=SCTempConst.xlsx

export TO BCC SUBJECT ATTCH SHDIR
./BNSendMail.sh

fi

the BNSendmail is as follows:

#!/bin/bash

cd ${SHDIR}
FROM="<from email id>"

boundary="ZZ_/afg6432dfgkl.94531q"
body=`cat msg.txt`

# Build headers
{

printf '%s\n' "From: $FROM
To: $TO
Cc: $CC
Bcc: $BCC
Subject: $SUBJECT
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=\"$boundary\"

--${boundary}
Content-Type: text/plain; charset=\"US-ASCII\"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

$body
"

mimetype1=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

printf '%s\n' "--${boundary}
Content-Type: $mimetype1
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"${ATTCH}\"
"

base64 "${SHDIR}/${ATTCH}"
echo

# print last boundary with closing --
printf '%s\n' "--${boundary}--"

} | sendmail -t -oi 

As I said this is working perfectly fine when execute manually. only when I set this as a cronjob, its not emailing.

any help is appreciated.

Thanks and regards, basu

11
  • what is you cron entry for this ? in cron you can set SHELL var to be executed within specific shell Commented Feb 16, 2015 at 12:59
  • May or may not be related: #!/usr/bin/sh isn't likely to be a valid shebang. Commented Feb 16, 2015 at 13:00
  • 1
    Did you try adding the full path instead of running as ./ ? Commented Feb 16, 2015 at 13:05
  • my crontab entry is as follows: Commented Feb 16, 2015 at 13:05
  • 00 05 * * * /export/home/oracle/CMC/scripts/utils/SCTempConst/SCTempConst_Mail. Commented Feb 16, 2015 at 13:06

1 Answer 1

1

Found the problem. it was not finding sendmail when executed through cron, I had to specify the full path of /usr/sbin/sendmail and it worked!

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.