Issue with cron and environmental variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with cron and environmental variable
# 1  
Old 07-23-2013
Issue with cron and environmental variable

My shell script it.sh.I am calling bip.sh from it.sh
Code:
#!/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

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

my error.log file

Code:
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.
ERROR: $ARBORDBU environment variable is not set

This script requires that the $ARBORDBU environment variable be set.

MY 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 &


The issue is with environment variables ARBORDBU,ARBOR_DB_PASSWD
When i call my script it.sh it executes successfully but when i am calling it through crontab it does not workSmilie
# 2  
Old 07-23-2013
cron has very limited idea about your shell environment, hence it would be better if you can set your profile again at the beginning of your script.

try editing your it.sh and add your ~/.profile or ~/.bashrc at the very beginning.

Code:
#!/bin/sh
#bring shell environment .

. /path/to/profile [full path to the file]

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
.....
.....

# 3  
Old 07-23-2013
Quote:
Originally Posted by codemaniac
cron has very limited idea about your shell environment, hence it would be better if you can set your profile again at the beginning of your script.

try editing your it.sh and add your ~/.profile or ~/.bashrc at the very beginning.

Code:
#!/bin/sh
#bring shell environment .

. /path/to/profile [full path to the file]

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
.....
.....

Hi Code ,
Thanks.
Can you tell what should i exactly write?

Should i write like this
Code:
#/.profile

or just
Code:
. /.profile

Thanks
Please tell me which syntax is correct and what should i write in my script.

Last edited by rafa_fed2; 07-23-2013 at 10:20 AM..
# 4  
Old 07-23-2013
first of all please check where the .profile file is located for the unix user.

Code:
. /path/to/the/profile

# 5  
Old 07-23-2013
Quote:
Originally Posted by codemaniac
first of all please check where the .profile file is located for the unix user.

Code:
. /path/to/the/profile

I checked that
In the path i gave
pwd
output-- /

then ls -alrt
.profile was there

---------- Post updated at 06:57 PM ---------- Previous update was at 06:47 PM ----------

Quote:
Originally Posted by codemaniac
first of all please check where the .profile file is located for the unix user.

Code:
. /path/to/the/profile



CODEMANIAC i dont know how to thank you.

I was stuck in this for past 15 hours.
Thank you very much.
Learned a new thing.
Can you tell me the exact reason for this though?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Clearing a environmental variable

i set a variable from the command line: export GANG="james,roy,martin" i can access this variable ($GANG) from a script. but each time i run the script, the variable keeps getting bigger. more info keeps getting added to it. Is there anyway i can make the $GANG variable contain the... (3 Replies)
Discussion started by: SkySmart
3 Replies

2. UNIX for Advanced & Expert Users

Environmental variable

i want to set environmental variables in solaris and redhat. it should show the current directory and the default shell should be bourne shell. along with it should show the hostname.. like this hostname{/home/vipin/data}# ifconfig Thanks in advanced.:wall: Please use code tags.... (1 Reply)
Discussion started by: vipinkumarr89
1 Replies

3. OS X (Apple)

.local hostname available as an environmental variable?

Hola - I've got a script for logon which populates a database with some info when a user logs on so that we can tell how many public terminals are in use & show users which ones are free. However, the machines are DHCPed and so using $HOSTNAME gives me an unstable name for them since of course... (3 Replies)
Discussion started by: gentinphilly
3 Replies

4. Shell Programming and Scripting

Setting Environmental Variable

I have a request from a programmer to set an env variable for him. I know how to do it for bash shell by adding the following line to .bash_profile export $VAR=/home/code/project/ But this will be applicable only when he is in his bash shell. What is the procedure to be followed to make... (2 Replies)
Discussion started by: Tuxidow
2 Replies

5. Shell Programming and Scripting

How to get the value of a variable which is having another value in environmental script?

Dear Folks, I am facing an issue in getting a value of a variable.Let me explain the scenario. I am having a list file say files.list in which I have mentioned 1 FILE1 2 FILE2 Then I am having an set_env.ksh in which I mentioned FILE1=/clocal/data/user/userdata.txt... (4 Replies)
Discussion started by: dinesh1985
4 Replies

6. UNIX for Dummies Questions & Answers

How does the PATH environmental variable work?

Hello. I have a question about how the PATH environment variable works. I wrote a script in $HOME/bin/gvim. I want it to be called instead of /usr/bin/gvim, so I've placed it before in the PATH. However, it is still the old one that is found. If I open an other terminal, I have the... (6 Replies)
Discussion started by: qwer
6 Replies

7. Shell Programming and Scripting

StartUp script Environmental Issue

Hi There, I have created a StartUp script which will create all alias's and export my path to GLOBAL so that i will be have some handy commands for simplifying my work My script code is like below ------------------------------------ #!/usr/bin/ksh set -o vi #Display the CURRENT USER... (5 Replies)
Discussion started by: Raamc
5 Replies

8. Shell Programming and Scripting

setting ksh environmental variable

Hi, I have problem setting up environmental variables. The idea is to start with main.ksh script that will run setting.ksh, and in side of it I'll set up variables. Please take a look at my code, and help me to find my mistake. Thanks, Mila Main.ksh look like this: #!/usr/bin/ksh #... (2 Replies)
Discussion started by: mefquik
2 Replies

9. Shell Programming and Scripting

Environmental Variable

Hi, I'm exporting an environmental variable from a C program using putenv function. I'm calling the exe of the C program from shell script. But when I display the environmental variables from the Shell script, My varaible is not getting displayed. Can anyone please tell me how to get it in... (2 Replies)
Discussion started by: janemary.a
2 Replies

10. Shell Programming and Scripting

Set Oracle Environmental Variable !!

Can someone send me a shell script to set all Oracle environment variable which is working. I have the following script which works but not 100%. Please advice what you think is wrong. if # Command executed from a terminal then ORACLE_SID="" ... (4 Replies)
Discussion started by: uuser
4 Replies
Login or Register to Ask a Question