[Solved] Shell not running through cron

Hi freinds,
I have tried running a script through cron ,it is a shell script which calls a oracle procedure , problem here is that there is function in sql code which makes a external C call , this function is failing when running manually but works when run manually.

I have trouble shooted various possibilities of giving complete absolute path and setting env variables given in CRON section ,but its not working.

Pls help with this
below is modified unix code

 
#!/bin/sh
 
. ~/.profile
#SHELL=/bin/ksh
#export SHELL
FNTMS_DIR="/usr1"
export FNTMS_DIR
ORACLE_SID=fntmsc
ORACLE_HOME="/dboracle/orabase/product/11.2.0.BTSP4"
export ORACLE_HOME
export ORACLE_SID
PATH=$ORACLE_HOME/bin:/usr1/ocms/bin:/usr/local/bin:$PATH
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr1/ntms/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH;
env > /tmp/mycron.env
FNTMS_DIR1="FNTMS_DIR=$FNTMS_DIR"
ORACLE_SID1="ORACLE_SID=$ORACLE_SID"
TCMS_USER1="TCMS_USER=$TCMS_USER"
TCMS_PASS1="TCMS_PASS=$TCMS_PASS"
OCMS_USER1="OCMS_USER=$OCMS_USER"
OCMS_PASS1="OCMS_PASS=$OCMS_PASS"
ORACLE_HOME1="ORACLE_HOME=\"$ORACLE_HOME\""
#chg for sqlldr.sh file in OCMS
sed -i 's#^.*FNTMS_DIR=.*$#'$FNTMS_DIR1'#g' $FNTMS_DIR/ocms/bin/sqlldr.sh
sed -i 's#^.*ORACLE_SID=.*$#'$ORACLE_SID1'#g' $FNTMS_DIR/ocms/bin/sqlldr.sh
sed -i 's#^.*OCMS_USER=.*$#'$OCMS_USER1'#g' $FNTMS_DIR/ocms/bin/sqlldr.sh
sed -i 's#^.*OCMS_PASS=.*$#'$OCMS_PASS1'#g' $FNTMS_DIR/ocms/bin/sqlldr.sh
sed -i 's#^.*ORACLE_HOME=.*$#'$ORACLE_HOME1'#g' $FNTMS_DIR/ocms/bin/sqlldr.sh
#FNTMS_DIR="/fnetemp/usr1"
if test ! -f /usr1/logs/ocms.log
then
        touch /usr1/logs/ocms.log
        chmod 777 /usr1/logs/ocms.log
fi
if test ! -f /usr1/logs/loadraw.log
then
        touch /usr1/logs/loadraw.log
        chmod 777 /usr1/logs/loadraw.log
fi
if test ! -f /usr1/ocms/status/ocms.running
then
    touch /usr1/ocms/status/ocms.running
        echo $ORACLE_HOME
        echo "a"
    /dboracle/orabase/product/11.2.0.BTSP4/bin/sqlplus ocmsmaster/s0lar1s @/usr1/ocms/bin/runocms 2>&1 >/usr1/ocms/status/debugmsgs
        /bin/rm /usr1/ocms/status/ocms.running
else
  echo OCMS already running
  :
fi
exit

also the original script is

#!/bin/sh
 
. ~/.profile
FNTMS_DIR1="FNTMS_DIR=$FNTMS_DIR"
ORACLE_SID1="ORACLE_SID=$ORACLE_SID"
TCMS_USER1="TCMS_USER=$TCMS_USER"
TCMS_PASS1="TCMS_PASS=$TCMS_PASS"
OCMS_USER1="OCMS_USER=$OCMS_USER"
OCMS_PASS1="OCMS_PASS=$OCMS_PASS"
ORACLE_HOME1="ORACLE_HOME=\"$ORACLE_HOME\""
#chg for sqlldr.sh file in OCMS
sed -i 's#^.*FNTMS_DIR=.*$#'$FNTMS_DIR1'#g' $FNTMS_DIR/ocms/bin/sqlldr.sh
sed -i 's#^.*ORACLE_SID=.*$#'$ORACLE_SID1'#g' $FNTMS_DIR/ocms/bin/sqlldr.sh
sed -i 's#^.*OCMS_USER=.*$#'$OCMS_USER1'#g' $FNTMS_DIR/ocms/bin/sqlldr.sh
sed -i 's#^.*OCMS_PASS=.*$#'$OCMS_PASS1'#g' $FNTMS_DIR/ocms/bin/sqlldr.sh
sed -i 's#^.*ORACLE_HOME=.*$#'$ORACLE_HOME1'#g' $FNTMS_DIR/ocms/bin/sqlldr.sh
#FNTMS_DIR="/fnetemp/usr1"
if test ! -f $FNTMS_DIR/logs/ocms.log
then
        touch $FNTMS_DIR/logs/ocms.log
        chmod 777 $FNTMS_DIR/logs/ocms.log
fi
if test ! -f $FNTMS_DIR/logs/loadraw.log
then
        touch $FNTMS_DIR/logs/loadraw.log
        chmod 777 $FNTMS_DIR/logs/loadraw.log
fi
if test ! -f $FNTMS_DIR/ocms/status/ocms.running
then
    touch $FNTMS_DIR/ocms/status/ocms.running
        ORACLE_SID=fntmsc
        ORACLE_HOME="/dboracle/orabase/product/11.2.0.BTSP4"
        echo $ORACLE_HOME
   export ORACLE_HOME
    export ORACLE_SID
    LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/lib64:/usr1/ntms/lib:$LD_LIBRARY_PATH
   export LD_LIBRARY_PATH;
        echo $LD_LIBRARY_PATH
    PATH=$ORACLE_HOME/bin:/usr1/ocms/bin:$PATH
        echo "a"
    $ORACLE_HOME/bin/sqlplus ocmsmaster/s0lar1s @$FNTMS_DIR/ocms/bin/runocms 2>&1 >$FNTMS_DIR/ocms/status/debugmsgs
        /bin/rm $FNTMS_DIR/ocms/status/ocms.running
else
  echo OCMS already running
  :
fi
exit

also function which is failing is

FUNCTION SystemCall(command IN VARCHAR2)
RETURN pls_integer
AS EXTERNAL
LIBRARY STDLIB
NAME "system"
PARAMETERS (command STRING,
            RETURN int);

Q1: Does the original script also in when called ny cron?

Q2: who's cron is being used?

Hi the problem got reolved when i chenged one of shell scripts from c shell to sh shell,
following is the original script,the script just checks that a file is present or not
script name - exists.sh

$ cat exist.sh_bkp
#!/bin/csh
 
#setenv LD_LIBRARY_PATH /usr/lib:/usr/openwin/lib:/usr/dt/lib
#setenv PATH /bin:/usr/bin:/usr/ccs/bin:/usr/ucb:/etc/sbin:/usr/sbin:/usr/dt/bin:/usr/local/bin:/opt/bin:/usr/openwin/bin:/usr/lib/nis:/usr/opt/SUNWmd/sbin:.
if [ -e  $1 ] 
then exit 0
else exit 1
fi

below given function runs through oracle,input parameters to this function is above script and one more file i.e SystemCall(exists.sh file_name)

FUNCTION SystemCall(command IN VARCHAR2)
RETURN pls_integer
AS EXTERNAL
LIBRARY STDLIB
NAME "system"
PARAMETERS (command STRING,
            RETURN int);

this function was returning 256 return code when exists.sh had c shell and returned 0 when it was with sh shell,can anyone pls tell the root cause for this,also the function is external call through oracle ,it calls C function system, can anyone explain system function (it o/p and operation) as its code is binary

1 Like

Thanks for keeping us informed!

Hi VBE,
actually i am looking for RCA of this issue.
could you please help with this?

You seem to be on a SOLARIS is it so?
What OS and version?

system details are

Linux 2.6.18-238.el5 #1 SMP Tue Jan 4 15:41:11 EST 2011 x86_64 x86_64 x86_64 GNU/Linux