Skip to Main Content

Infrastructure Software

Announcement

Testing banner

Cronjob doesn't execute shell script, but executing it outside of cron

User_UB5IKJan 9 2023 — edited Jan 9 2023

I tried to schedule the backup script and cronjob doesn't work but it worked from outside of crontjob.
00 01 * * * /u02/backup/script/exp_myhr.sh >> /dev/null 2>&1
Even I tried to execute/source executing the oraenv script oraenv and/or .bash_profile in the script, the cronjob is still not execute as the schedule. Both cronjob tasks run as Oracle or root are not working.

my script is:
#!/bin/bash
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export ORACLE_SID=myhr
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$PATH:$HOME/.local/bin:$HOME/bin:$ORACLE_HOME:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:/sbin:/bin:/usr/sbin:/usr/bin
#. /usr/local/bin/oraenv > /dev/mull
# . /home/oracle/.bash_profile > /dev/mull
. oraenv
timestamp=`date +%m-%d-%y-%H%M%S`
#runtime="$(date +'%m_%d_%Y_%H%M%S')"
export timestamp
export runtime
export EXP_PATH=/u02/backup/$ORACLE_SID/exp_${ORACLE_SID}_full
export LOGFILENAME=daily_exp_${ORACLE_SID}_${timestamp}.log
export DUMPFILE=daily_exp_${ORACLE_SID}_${timestamp}.dmp

# Delete dump and log files older than 7 days
echo "Recycle old dumpfile over 7 days"
find /u02/backup/export/daily_exp_myhr_*.dmp -mtime +7 -exec rm {} \;
find /u02/backup/export/daily_exp_myhr_*.log -mtime +7 -exec rm {} \;
echo ""

# Back up
echo "Starting backup at $timestamp, please wait..."
echo "Export file: $LOGFILENAME"
echo "Begin datapump export of $ORACLE_SID"
date
echo sid=${ORACLE_SID}
echo DUMPFILE=${DUMPFILE}
echo LOGFILENAME=${LOGFILENAME}
expdp system/Password*1234 DUMPFILE=${DUMPFILE} LOGFILE=${LOGFILENAME} DIRECTORY=EXP_MYHR FULL=y
echo "End datapump export of $ORACLE_SID"
exit
----------------------
[oracle@j ~]$ cd $ORACLE_HOME
[oracle@j dbhome_1]$ pwd
/opt/oracle/product/19c/dbhome_1

When I sort the env to output, the oracle_home is set
DISPLAY=localhost:10.0
HISTCONTROL=ignoredups
HISTSIZE=1000
HOME=/home/oracle
HOSTNAME=j
LANG=en_US.UTF-8
LC_ALL=C
LD_LIBRARY_PATH=/opt/oracle/product/19c/dbhome_1/lib
LESSOPEN=||/usr/bin/lesspipe.sh %s
LOGNAME=oracle
MAIL=/var/spool/mail/oracle
OLDPWD=/home/oracle
ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
ORACLE_SID=myhr

what is my error here?
Thank you,
BN

Comments
Post Details
Added on Jan 9 2023
1 comment
14 views