Another issue with crontab

My shell script it.sh

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y  %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR


LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file 
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID


### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<<EOF>$CUR_DIR/sql_output.txt
set feedback off
set heading off
select  1016 from adj where rownum <2;
EOF


if [ $? -eq 0 ] 
then 
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are  "



if [  ! -s  "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt" 
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 0 $i >  $CUR_DIR/bip_log_1.txt
sleep 100
done
fi


###Removing temporary log files generated 

if [  -f  $CUR_DIR/bip_log_1.txt ]
then
`rm  $CUR_DIR/bip_log_1.txt`
 echo "file bip__log_1.txt removed"
fi

if [  -f  $CUR_DIR/sql_output.txt ]
then
`rm  $CUR_DIR/sql_output.txt`
 echo "sql_output.txt removed"
fi

when i execute the script manually ,it is working fine but when i schedule this job in crontab i get an error in error.log

Why?
Please help me.

crontab entry

59 04 * * *  /arbor/integ_fx/rahul_raj/itsr_5652/it.sh /arbor/integ_fx/rahul_raj/itsr_5652

LOGGING STARTS 07-22-2013  05:22:00


SQLPLUS CONNECTION
 SQLPLUS Connection Successful
bip 1016 is running
cat: cannot open /.arborpw
file bip__log_1.txt removed
sql_output.txt removed

change this

cd $SCRIPT_DIR
sh bip.sh 01 0 $i >  $CUR_DIR/bip_log_1.txt

to

sh  $SCRIPT_DIR/bip.sh 01 0 $i >  $CUR_DIR/bip_log_1.txt

Hi i am still getting the same error

I don't know what's going on with all this cat $CUR_DIR stuff.

Surely it should be more like

grep "^USER_ID" $CUR_DIR/.id_pass_file.txt | ...

CUR_DIR is surely a variable storing the "current directory", and not a file whose contents are to be prefixed to some string and piped to grep

HI scott

SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID

.id_pass_file.txt is a configuration file storing the password username ,sid and path of the shell script.i am just fetching the username ,password from them,.the cionnection is also successfull .But i dont understand the error that i am getting

Ignore me, I think I'm sleep deprived!

Anyway, I've removed all the pointless cat's and replaced backticks with $() or removed pointless ones.

And added set -x for some trace. Please run it and post the output.

#!/bin/sh

set -vx

ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=$(date "+%m-%d-%Y  %H:%M:%S"); export today
CUR_DIR=$1; export CUR_DIR


LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file 
SCRIPT_DIR=$(grep "^SCRIPT_DIR" $CUR_DIR/.id_pass_file.txt | cut -d "=" -f2)
export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=$(grep "^USER_ID" $CUR_DIR/.id_pass_file.txt | cut -d "=" -f2)
export USER_ID

PWD=$(grep "^PWD" $CUR_DIR/.id_pass_file.txt | cut -d "=" -f2)
export PWD

SID=$(grep "^SID" $CUR_DIR/.id_pass_file.txt | cut -d "=" -f2)
export SID


### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD << EOF > $CUR_DIR/sql_output.txt
set feedback off
set heading off
select  1016 from adj where rownum <2;
EOF


if [ $? -eq 0 ] 
then 
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are  "



if [  ! -s  "$CUR_DIR/sql_output.txt" ]
then
  echo "No account number for bad debt" 
  else
  while read LINE; do
    echo "bip $i is running"
    cd $SCRIPT_DIR
    sh bip.sh 01 0 $i > $CUR_DIR/bip_log_1.txt ### Append to this one file, or a new file for each one?
    sleep 100
  done < $CUR_DIR/sql_output.txt
fi


###Removing temporary log files generated 

if [ -f  $CUR_DIR/bip_log_1.txt ]
then
 rm  $CUR_DIR/bip_log_1.txt
 echo "file bip__log_1.txt removed"
fi

if [  -f  $CUR_DIR/sql_output.txt ]
then
 rm  $CUR_DIR/sql_output.txt
 echo "sql_output.txt removed"
fi

Script did not ran

ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
ORACLE_HOME=/var/opt/oracle/product/10g
+ export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
PATH=/arbor/integ_fx/bin:/bin:/var/opt/oracle/product/10g/bin:/usr/cobol/bin:/arbor/integ_fx/bin:/arbor/3p/python/bin:/arbor/3p/rosette/bin:/arbor/3p/xerces/bin:/arbor/3p/xalan/bin:/arbor/3p/ACE_wrappers/bin:/arbor/3p/perl/bin:/app/tuxedo/tuxedo9.0/bin:/usr/java/bin:/var/opt/oracle/product/10g/bin:/arbor/3p/pgsql/bin:/arbor/integ_fx/opcntr/agent/bin:/arbor/integ_fx/opcntr/cc/bin:/arbor/integ_fx/DataBlitz/bin:/usr/bin:/sbin:/usr/sbin:/var/opt/oracle/product/10g/bin:/arbor/integ_fx/bin:/bin:/var/opt/oracle/product/10g/bin:/usr/cobol/bin:/arbor/integ_fx/bin:/arbor/3p/python/bin:/arbor/3p/rosette/bin:/arbor/3p/xerces/bin:/arbor/3p/xalan/bin:/arbor/3p/ACE_wrappers/bin:/arbor/3p/perl/bin:/app/tuxedo/tuxedo9.0/bin:/usr/java/bin:/var/opt/oracle/product/10g/bin:/arbor/3p/pgsql/bin:/arbor/integ_fx/opcntr/agent/bin:/arbor/integ_fx/opcntr/cc/bin:/arbor/integ_fx/DataBlitz/bin:/usr/bin:/sbin:/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/ucb:/etc:.:/usr/local/bin:/opt/openv/netbackup/bin:/usr/lib/vxvm/bin:/opt/sfw/bin:/opt/csw/bin:/var/opt/oracle/product/10g/bin:/bin:/usr/bin
+ export PATH
today=$(d./it.sh: syntax error at line 7: `today=$' unexpected
integfx:/arbor/integ_fx/rahul_raj/itsr_5652>

Ah, Solaris!

Hang on...

I didn't do anything here, except put the backticks back, and quote some variables.

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g
export ORACLE_HOME

PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin
export PATH

today=`date "+%m-%d-%Y  %H:%M:%S"`
export today

CUR_DIR=$1
export CUR_DIR

LOG_FILE="$CUR_DIR/error.log"
export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file 
SCRIPT_DIR=`grep "^SCRIPT_DIR" "$CUR_DIR/.id_pass_file.txt" | cut -d "=" -f2`
export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`grep "^USER_ID" "$CUR_DIR/.id_pass_file.txt" | cut -d "=" -f2`
export USER_ID

PWD=`grep "^PWD" "$CUR_DIR/.id_pass_file.txt" | cut -d "=" -f2`
export PWD

SID=`grep "^SID" "$CUR_DIR/.id_pass_file.txt" | cut -d "=" -f2`
export SID


### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD << EOF > "$CUR_DIR/sql_output.txt"
set feedback off
set heading off
select  1016 from adj where rownum <2;
EOF


if [ $? -eq 0 ] 
then 
  echo " SQLPLUS Connection Successful "
else
  echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are  "



if [ ! -s  "$CUR_DIR/sql_output.txt" ]
then
  echo "No account number for bad debt" 
  else
  while read LINE; do
    echo "bip $i is running"
    cd "$SCRIPT_DIR"
    sh bip.sh 01 0 "$LINE" >> "$CUR_DIR/bip_log_1.txt" ### Append to this one file, or a new file for each one?
    sleep 100
  done < "$CUR_DIR/sql_output.txt"
fi


###Removing temporary log files generated 

if [ -f  "$CUR_DIR/bip_log_1.txt" ]
then
 rm  "$CUR_DIR/bip_log_1.txt"
 echo "file bip__log_1.txt removed"
fi

if [ -f "$CUR_DIR/sql_output.txt" ]
then
 rm  "$CUR_DIR/sql_output.txt"
 echo "sql_output.txt removed"
fi

Scott lol.

Can you modify my script please

SYNTAX ERRIOR

./it.sh: syntax error at line 26: `SCRIPT_DIR=$' unexpected

I missed one $(...). Fixed in post. I have no solaris to test, so sorry about that!

i am getting these errors

SQLPLUS CONNECTION
 SQLPLUS Connection Successful
bip  is running
libarbor_db/database_gen.c(4670): arb_db_err - Entry
   errtype           = 2
   exec_user_handler = 1
   errcode           = 936
   errtext           = Error in execution of OCI function unused:
retcode = -1 (OCI_ERROR)
ORA-00936: missing expression

   errsev            = 2
   errproc           = unknown
   line_no           = 0
   query             = 10053aba0

This is a different problem now. It looks like an issue with your oracle installation or environment. Can you run SQL OK from the command line?

Try setting your oracle environment using oraenv, not manually like this.

Scott

With your code i am able to connect oracle.Its working fine.
seet the log

Oh yes, I missed that.

You'll have to debug bip.sh to see what's going wrong in there.

Well thanks SCott for your time.

Well bip.sh is standard shell script they use.i am not allowed to change anything.

could you see my another question.Resolve that issue only

I deleted your other thread - that could easily have been sorted out here.

There's no need for an if, when a force would do:

rm -f "$CUR_DIR/bip_log_1.txt" && echo bip_log removed
rm -f "$CUR_DIR/sql_output.txt" && echo sql_output removed

In case of abnormal program termination, you could also remove the files using a trap, if you wanted.

Lo ok thanks.I was searching for it :smiley:

Well my last issue for you

This is my final code working well

#!/bin/sh
ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH
today=`date "+%m-%d-%Y  %H:%M:%S"`; export today
CUR_DIR=$1; export CUR_DIR


LOG_FILE=$CUR_DIR/error.log; export LOG_FILE

# Direct script output to log
exec > $LOG_FILE 2>&1

echo
echo
echo "LOGGING STARTS $today"
echo
echo
###Fetching the script directory from configuration file 
SCRIPT_DIR=`cat $CUR_DIR/.id_pass_file.txt | grep "^SCRIPT_DIR" | cut -d "=" -f2`; export SCRIPT_DIR

### Credentials for SQLPLUS

USER_ID=`cat $CUR_DIR/.id_pass_file.txt | grep "^USER_ID" | cut -d "=" -f2`; export USER_ID
PWD=`cat $CUR_DIR/.id_pass_file.txt | grep "^PWD" | cut -d "=" -f2`; export PWD
SID=`cat $CUR_DIR/.id_pass_file.txt | grep "^SID" | cut -d "=" -f2`; export SID


### Connecting ORACLE

echo "SQLPLUS CONNECTION"

sqlplus -s $USER_ID@$SID/$PWD<<EOF>$CUR_DIR/sql_output.txt
set feedback off
set heading off
select distinct account_no from adj  WHERE ADJ_TRANS_CODE=-2401  and request_status=1  and bill_ref_no=0
order by account_no;
EOF


if [ $? -eq 0 ] 
then 
echo " SQLPLUS Connection Successful "
else
echo " SQLPLUS Connection Failed "
fi

##echo " The account numbers to be used in BIP are  "



if [  ! -s  "$CUR_DIR/sql_output.txt" ]
then
echo "No account number for bad debt" 
else
for i in `cat $CUR_DIR/sql_output.txt`
do
echo "bip $i is running"
sh  $SCRIPT_DIR/bip.sh 01 0 $i >  $CUR_DIR/bip_log_1.txt
sleep 100
done
fi


###Removing temporary log files generated 

if [ -f  "$CUR_DIR/bip_log_1.txt" ]
then
 rm  "$CUR_DIR/bip_log_1.txt"
 echo "file bip__log_1.txt removed"
fi

if [ -f "$CUR_DIR/sql_output.txt" ]
then
 rm  "$CUR_DIR/sql_output.txt"
 echo "sql_output.txt removed"
fi

rm  $CUR_DIR/error.log

When i execute it manually it works well.But when i schdelue it i get an error


SQLPLUS CONNECTION
 SQLPLUS Connection Successful
bip 1016 is running
cat: cannot open /.arborpw
file bip__log_1.txt removed
sql_output.txt removed

I am not able to debug it.

What is this cat: cannot open /.arborpw.

It is not affecting my functionality though but still

It clearly comes from bip.sh. You'll need to look there for clues.

If it's bugging you, but you're not able to fix it, you can try this:

sh  $SCRIPT_DIR/bip.sh 01 0 $i >  $CUR_DIR/bip_log_1.txt 2> /dev/null

Scott you are right and it is affecting my functionality too now

I am posting the BIP.SH
CODE

#!/bin/sh
ARBOR_DB_PASSWD=`cat $ARBORDIR/.arborpw`; export ARBOR_DB_PASSWD
DB_PASS=$ARBOR_DB_PASSWD; export DB_PASS;
ORACLE_SID=$ARBOR_CATALOG_DATABASE; export ORACLE_SID;
ARBORCTRLRPT03=$ARBORDATA/reports/ctrl; export ARBORCTRLRPT03;

Usage(){
  echo "\n\n  Usage is: `basename $0` <proc_num> <bip mode> <account_no>\n"
  echo "  where <proc_num> is a number between 01 and 99"
  echo "        <bip_mode> is a number. Use 0=production, 3=proforma, 6=backout"
  echo "        <bip_mode> is an arbor accout number\n\n"
  exit 0
}

#  Check number of arguments
if [ "$#" -ne 3 ] ; then
  Usage
fi

# Check to see if ARBORDBU is set
if [ -z "${ARBORDBU}" ] ; then
        echo "ERROR: \$ARBORDBU environment variable is not set\n"
        echo "This script requires that the \$ARBORDBU environment variable be set.\n\n"
        exit 1
fi

# Check to see if DB_PASS is set
if [ -z "${DB_PASS}" ] ; then
        echo "ERROR: \$DB_PASS environment variable is not set\n"
        echo "This script requires that the \$DB_PASS environment variable be set.\n\n"
        exit 1
fi

# Check to see if ORACLE_SID is set
if [ -z "${ORACLE_SID}" ] ; then
        echo "ERROR: \$ORACLE_SID environment variable is not set\n"
        echo "This script requires that the \$ORACLE_SID environment variable be set.\n\n"
        exit 1
fi

# Set the variables for arguments passed by the user
PROCNAME=bip$1
BIP_MODE=$2
ACCOUNT=$3

# Get the database from the user's environment
DB=$ORACLE_SID

# Set this so that the process doesn't try to connect to Operations Center
OAM_ENV_CONN_MA=FALSE
export OAM_ENV_CONN_MA


# Log into sqlplus, delete any existing entries, and make the new entry
sqlplus -s $ARBORDBU/$DB_PASS@$DB <<END

update SYSTEM_PARAMETERS set int_value=1 where module='BIP' and parameter_name='TRA_SWITCH';
delete from PROCESS_SCHED where process_name = '$PROCNAME';
delete from PROCESS_STATUS where process_name = '$PROCNAME';
insert into PROCESS_SCHED values('$PROCNAME','$PROCNAME','N',$BIP_MODE,SYSDATE,86400,0,2,55,'$DB','CMF.account_no in ($ACCOUNT)',1,NULL,0,NULL,0);
commit;
exit

END

echo "Starting BIP in the background with process name = \"$PROCNAME\""
BIP $PROCNAME 3 &

Please tell what should i modify.I cant change the bip.sh