[Solved] Shell not running through cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Shell not running through cron
# 1  
Old 11-22-2012
[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

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

Code:
#!/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
Code:
FUNCTION SystemCall(command IN VARCHAR2)
RETURN pls_integer
AS EXTERNAL
LIBRARY STDLIB
NAME "system"
PARAMETERS (command STRING,
            RETURN int);


Last edited by Jcpratap; 11-27-2012 at 08:14 AM..
# 2  
Old 11-22-2012
Q1: Does the original script also in when called ny cron?

Q2: who's cron is being used?
# 3  
Old 11-23-2012
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

Code:
$ 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)

Code:
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

Last edited by Jcpratap; 11-27-2012 at 08:14 AM..
This User Gave Thanks to Jcpratap For This Post:
# 4  
Old 11-23-2012
Thanks for keeping us informed!
# 5  
Old 11-27-2012
Hi VBE,
actually i am looking for RCA of this issue.
could you please help with this?
# 6  
Old 11-27-2012
You seem to be on a SOLARIS is it so?
What OS and version?
# 7  
Old 11-27-2012
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Troubles running DB2 command in shell script via cron

Hi there, Now I'm facing error regarding running shell script via cron. The shell script which is required to get value from database. Below is the main part of shell script. #/bin/bash #connect to database(1) db2 connect to $database user xxxx using yyyy #set values from... (3 Replies)
Discussion started by: Rohan Kishibe
3 Replies

2. Shell Programming and Scripting

Running shell script via cron

Hi Guys, I do have a shell script that I scheduled to run via the cron but when the script don't run. But when I run the script manually it does run perfectly... What might be the problem? Thanks. (1 Reply)
Discussion started by: Phuti
1 Replies

3. Shell Programming and Scripting

Running Shell Script in the cron, background process

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (9 Replies)
Discussion started by: blacksteel1988
9 Replies

4. Shell Programming and Scripting

Running Shell Script in the cron, background proccess

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (0 Replies)
Discussion started by: blacksteel1988
0 Replies

5. OS X (Apple)

[Solved] Running shell code in AppleScript without Terminal

What I want my script to do is to run a command in Terminal and close that same Terminal window when the process is complete. Of course I could ad a delay of 6 seconds to complete the process, but it may not be enough every time. To simplify my question, this is what I want to achieve.... (9 Replies)
Discussion started by: ShadowofLight
9 Replies

6. Shell Programming and Scripting

[Solved] Error while running on Cron

All, I am running one perl script from prompt and its running fine, but while putting it on cron gives below error, DB-Library error: Could not open interface file. (2 Replies)
Discussion started by: Deei
2 Replies

7. Shell Programming and Scripting

URGENT: cron job not running the sqlplus command in shell script

cron job not running the sqlplus command in shell script but the shell script works fine from command line.. Cronjob: 5 * * * * /home/dreg/script.sh script.sh: #!/bin/ksh /oracle/u000/app/oracle/product/10204/GEN/bin/sqlplus -s <user>/<pass>@<sid/home/dreg/sqlscript.sh ... (18 Replies)
Discussion started by: Ikea
18 Replies

8. Shell Programming and Scripting

Running a shell script in cron...email not sending - help??

I am pretty new to Unix shell scripting, but wondered if anyone could help (in layman's terms if possible!!) :) I have a shell script which ultimately sends an alert to an email address if part of a batch of programs fails. Here's the script that sends the email: Script: 6check.csh... (8 Replies)
Discussion started by: tjhorwood
8 Replies

9. Shell Programming and Scripting

error in running shell script in cron

#!/bin/bash CLASSPATH=. #CLASSPATH=${CLASSPATH}:${INSTALL_PATH}home/squidlog/CopyFile.java CLASSPATH=${CLASSPATH}:${INSTALL_PATH}usr/java/latest/lib/*.jar javac CopyFile.java echo "CLASSPATH=$CLASSPATH" #home/wbiadmin/JRE1.4.2/j2re1.4.2_15/bin/java CopyFile /usr/bin/java... (3 Replies)
Discussion started by: sari
3 Replies

10. UNIX for Dummies Questions & Answers

Cron running shell scripts.

What are the rules of calling shell scripts in cron. How do I go about setting up the correct PATHS that calls a script, which then calls another sub script all of which has to retain the orginal PATHS and VARS that I've set up in first script Confused.. ok Well Cron calls a script... (3 Replies)
Discussion started by: cfoxwell
3 Replies
Login or Register to Ask a Question