1

Can someone please help me here. My cron job is not sending an email with output. While I run the shell script manually it generates an email with output.

Here is the script looks like

#!/bin/bash

MAILLIST=<email>
LogDirectory='/app/oracle/admin/monitor/'

DBUSER='rman'
DBUSERPASSWORD='rman01'
DB='pdcatdb'
SUBJECT="RMAN Backup Status Report"
ORACLE_HOME=/app/oracle/product/12.1.0.2_64

${ORACLE_HOME}/bin/sqlplus -s <<EOF  > ${LogDirectory}/query.log
${DBUSER}/${DBUSERPASSWORD}@${DB}
set pagesize 20000
set linesize 2000
set wrap off
set trimspool on
set feedback off
set echo off
set termout off
set heading off
set underline off
set colsep ','
SELECT RTRIM(A.DB_NAME)||'---->'||
       LTRIM(A.STATUS) "BACKUP_STATUS"
  FROM rman.RC_RMAN_STATUS A,
       (  SELECT DB_NAME, OBJECT_TYPE, MAX (END_TIME) END_TIME
            FROM rman.RC_RMAN_STATUS
           --WHERE     OBJECT_TYPE IN ('DB FULL', 'DB INCR')
           WHERE     OBJECT_TYPE IN ('DB INCR')
                 AND STATUS IN ('COMPLETED', 'COMPLETED WITH ERRORS', 'FAILED')
                 AND OPERATION IN ('BACKUP', 'BACKUP COPYROLLFORWARD')
        GROUP BY DB_NAME, OBJECT_TYPE) B
 WHERE     A.OBJECT_TYPE IN ('DB FULL', 'DB INCR', 'ARCHIVELOG')
       AND STATUS IN ('COMPLETED', 'COMPLETED WITH ERRORS', 'FAILED')
       AND OPERATION IN ('BACKUP', 'BACKUP COPYROLLFORWARD')
       AND A.DB_NAME = B.DB_NAME
       AND A.END_TIME = B.END_TIME
       AND A.OBJECT_TYPE = B.OBJECT_TYPE
       AND A.end_time > sysdate-7
       order by 1
       /
EOF
mailx -s "Rman Backup Report" <email> < /app/oracle/admin/monitor/query.log
7
  • Your mailx command at the bottom of the script appears to reference explicit emails. Is this different from the unused MAILLIST variable at the top of the script? (You also define $SUBJECT and $LogDirectory but neither is used in the mailx command you've shown.)
    – roaima
    Jul 14 '15 at 22:07
  • @roaima, I commented all the variables that I've not used and tried, no luck. I also commented all the variables and ran the script by specifying full path, still no luck.
    – Ravikanth
    Jul 14 '15 at 23:09
  • Please can you show the crontab entry for this command. What errors do you get, if any, as the cron output (not your mailx output as you've already said that's empty).
    – roaima
    Jul 14 '15 at 23:20
  • 1
    Thank you all, my sctipt is working now after adding source /home/user/.bash_profile, Thank you so much for your help!
    – Ravikanth
    Jul 15 '15 at 14:27
  • 1
    @Ravikanth: If steve's answer solved your problem, you should "accept" it by clicking the check mark to the left of the answer. Jul 17 '15 at 12:45
2

Those environment variables such as ${ORACLE_HOME} are perhaps in your bash profile. This does not get read via cron automatically.

Insert the line below after the #!/bin/bash.

source /home/user/.bash_profile
3
  • $ORACLE_HOME is defined near the top of the script
    – roaima
    Jul 14 '15 at 22:06
  • Thank you for responding, when I added the line, it is throwing below error ./rman_backup_report.sh: line 2: /home/user/.bash_profile: No such file or directory infact, If you look at my script I've defined these in my script as a variables DBUSER='rman' DBUSERPASSWORD='rman01' DB='pdcatdb' SUBJECT="RMAN Backup Status Report" ORACLE_HOME=/app/oracle/product/12.1.0.2_64
    – Ravikanth
    Jul 14 '15 at 22:21
  • 1
    @steve, Thank you so much , I added the bash_profile to my script and it works like charm! Thank you!
    – Ravikanth
    Jul 15 '15 at 14:26

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.