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.) Commented Jul 14, 2015 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
    Commented Jul 14, 2015 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). Commented Jul 14, 2015 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
    Commented Jul 15, 2015 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. Commented Jul 17, 2015 at 12:45

2 Answers 2

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 Commented Jul 14, 2015 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
    Commented Jul 14, 2015 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
    Commented Jul 15, 2015 at 14:26
-1

Sorry I have to resurrect this because I was googling this the simple solution is (at least in my case) to use shebang

#!/bin/csh

because orasid uses this shell as standard shell

1
  • 1
    There is some assumption about where the Oracle environment is being set up that you do not mention. In your case, it may be in the csh shell's initialization file. However, for the user in the question it seems to be in their .bash_profile file.
    – Kusalananda
    Commented Feb 28, 2023 at 9:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .