Executing Sql Query Using Shell Script

HI ALL
i have a requirement like this. i have to write a shell script to run a sql query. DB is oracle. once the query is run, the results of the query has to be published in a data file. can you please advice me how to go about it. i am absolutely new to shell scripts and this is a part of my job.

This question is answered several times a week; please search the forums.

thanks for the reply, i am new to this group and I will look for the posts

This post may get you started.

try this

DATA=`echo "SET HEADING OFF;\n SET FEED OFF;\n select <whatever query you want here > ;\n exit\n"|sqlplus -s /`

echo $DATA > <whatver file you want>

hi

i tried your query. when i execute that i am getting an error like this "SQL plus cant be found" is there a way not to mention the user name and pwd in the script. thanks

Not exactly as you have asked but that doesn't sound like your problem. Here is one method:

sqlplus -s /nolog <<EOF > youroutputfile
connect un/pw@db            <== login credentials inside here document
<your sql>;
EOF

If sqlplus can't be found then ${ORACLE_HOME}/bin is not in your path. If that is not in your path then you probably didn't prepare your environment properly by invoking /usr/local/bin/oraenv.

EXPORT ORACLE_SID=yoursid
EXPORT ORAENV_ASK=N
. /usr/local/bin/oraenv

sqlplus -s /nolog <<EOF > youroutputfile
connect ...
...
EOF

You can also use a named pipe to log in to the database as follows:

mknod /tmp/loginfile.sql p

print "connect un/pw" > /tmp/loginfile.sql &       <== login credentials in a sql script temporarily
sqlplus -s /nolog <<EOF > youroutputfile
@/tmp/loginfile.sql
...
EOF

You must provide login credentials in order to query the database. Your DBA can configure accounts that allow you to not specify any username or password as you have been given examples for. If your DBA defines accounts using OPS$ prefix, then you can log in as follows:

sqlplus -s / <<EOF >yourloginfile.sql    <== login credentials tied to your os login
...
EOF

thanks for your reply markile..

in here, the user name and password are stored in a particular directory (batchuse/user.ksh). I have to retrieve the user names from there. how will i do that.

if i have to store the results of a query in a particular file, how do i give the path of the file wher to store.

thanks again

Hi,

Can anybody explain me the following code. Can you tell me how i need to modify this code to incorporate my scenario.

START OF CODE

umask 000
#
# Source in the home profile
#
if [ -f $HOME/.profile ]
then
. $HOME/.profile
else
echo "ERROR: Error sourcing $HOME/.profile !" >> $EBPP_DATAFEED_LOGFILE
exit 10
fi

TMP_OUTPUT_FILE="temp_log.tmp"
TMPBATCHPROC="temp_batch.tmp"

export CURRENT_FEED=`date +%Y-%m-%d`
#
# Source in the environment variables (if possible)
#
if [ -f ./eBPPDataFeed_env.rc ]
then
. ./eBPPDataFeed_env.rc
fi
#

# Set the error codes
#
. ./errorcodes.ksh
#
# Obtain the secure username and password (if it exists)
#
if [ -f "$BATCH_USER_DIR/batch_user.ksh" ]
then
TMPPWD=`pwd` # v1.1
cd $BATCH_USER_DIR # v1.1
. ./batch_user.ksh # v1.1
RTNCD=$? # v1.1
cd $TMPPWD # v1.1
if [ $RTNCD = 0 ]
then
export SIEBEL_USERNAME=$USERID
export SIEBEL_PASSWORD=$PASSWORD
else
exit $EXIT_BATCHUSER_FAILED
fi
else
echo "ERROR: batch_user.ksh does not exist, unable to source in variables" >> $EBPP_DATAFEED_LOGFILE
exit $EXIT_BATCHUSER_DOESNOTEXIST
fi
#
# Check if the Environment Variables are set, if not, exit -1
#
for i in SIEBEL_USERNAME SIEBEL_PASSWORD \
EBPP_DATAFEED_ROOT EBPP_DATAFEED_DATA EBPP_DATAFEED_SCRIPTS EBPP_DATAFEED_LOGS \
SIEBEL_DB_USERNAME SIEBEL_DB_PASSWORD SIEBEL_DB_ORACLESID SIEBEL_DB_TABLE_OWNER \
SIEBEL_ROOT EXIT_SUCCESS EXIT_ENV_MISSING EXIT_ENV_NOVALUE \
EXIT_SQLPLUSERROR EXIT_BATCHUSER_FAILED EXIT_BATCHUSER_DOESNOTEXIST MINERRORLEVEL
do

IS_SETF1=\`env | grep "^$i=" | cut -d= -f1\`
if [[ -z $IS_SETF1 ]]
then
    echo "FATAL: Environment Variable $i is not set, terminating process" &gt;&gt; $EBPP\_DATAFEED_LOGFILE
    exit $EXIT\_ENV_MISSING
fi

IS_SETF2=\`env | grep "^$i=" | cut -d= -f2\`
if [[ -z $IS_SETF2 ]]
then
    echo "FATAL: Environment Variable $i has no value, terminating process" &gt;&gt; $EBPP\_DATAFEED_LOGFILE
    exit $EXIT\_ENV_NOVALUE
fi

done
#
echo "main> INFO: Running eBPP Profile Data Feed Process with Table Owner $SIEBEL_DB_TABLE_OWNER @ `date`" >> $EBPP_DATAFEED_LOGFILE
# Let us know what we are doing
# Get the last feed date from system preferences and store in variable#

   LAST_FEED=\`sqlplus -S $SIEBEL\_DB\_USERNAME/$SIEBEL\_DB\_PASSWORD@$SIEBEL\_DB_ORACLESID &lt;&lt;!
    SET HEAD OFF
    SET FEEDBACK OFF
    SET PAGESIZE 0
    SET LINESIZE 900
    SELECT VAL FROM $SIEBEL\_DB\_TABLE\_OWNER.S\_SYS_PREF where SYS\_PREF_CD = 'ALLTEL - EBPP Profile Feed';
    QUIT;

!`

RTNCD=$?
if [[ ! 0 = $RTNCD ]]
then
echo "ERROR: SQLPLUS Failed when searching for system preferences" >> $EBPP_DATAFEED_LOGFILE
cat $EBPP_DATAFEED_LOGFILE
exit $EXIT_SQLPLUSERROR
fi

echo "main> INFO: Last eBPP Data Feed Date" $LAST_FEED >>$EBPP_DATAFEED_LOGFILE
echo "main> INFO: Current eBPP Data Feed Date" $CURRENT_FEED >> $EBPP_DATAFEED_LOGFILE
echo "main> INFO: Start Extracting eBPP Data Feed file `date`" >> $EBPP_DATAFEED_LOGFILE

# Extract data feed and make dat file and save in data directory
# exit -1

sqlplus -S $SIEBEL_DB_USERNAME/$SIEBEL_DB_PASSWORD@$SIEBEL_DB_ORACLESID > $EBPP_DATAFEED_DATAFILE <<!
SET HEAD OFF
SET FEEDBACK OFF
SET PAGESIZE 0
SET LINESIZE 900
-- This part of the query will pick up any B2C profile changes.
SELECT ''||ORG.X_BILL_ACCT_NUM||'|'||CON.EMAIL_ADDR||'|'||PROF.X_PAPER_BILL_FLG||''
FROM $SIEBEL_DB_TABLE_OWNER.S_CONTACT CON,
$SIEBEL_DB_TABLE_OWNER.S_ORG_EXT ORG,
$SIEBEL_DB_TABLE_OWNER.S_USER_PROF PROF
WHERE ORG.ROW_ID = CON.PR_DEPT_OU_ID
AND PROF.PAR_ROW_ID = CON.ROW_ID
AND PROF.LAST_UPD >= TO_DATE('$LAST_FEED','yyyy-mm-dd')
AND ORG.X_BILL_ACCT_NUM IS NOT NULL
AND ORG.X_B2B_ACCOUNT IS NULL
AND PROF.X_PAPER_BILL_FLG IS NOT NULL
UNION
-- This part of the query will pick up any B2B profile changes.
SELECT ''||ORG.X_BILL_ACCT_NUM||'|'||CON.EMAIL_ADDR||'|'||PROF.X_PAPER_BILL_FLG||''
FROM $SIEBEL_DB_TABLE_OWNER.S_CONTACT CON,
$SIEBEL_DB_TABLE_OWNER.S_ORG_EXT ORG,
$SIEBEL_DB_TABLE_OWNER.S_USER_PROF PROF
WHERE ORG.PR_CON_ID = CON.ROW_ID
AND PROF.PAR_ROW_ID = ORG.ROW_ID
AND PROF.LAST_UPD >= TO_DATE('$LAST_FEED','yyyy-mm-dd')
AND ORG.X_BILL_ACCT_NUM IS NOT NULL
AND ((ORG.X_B2B_ACCOUNT = 'Y') or (ORG.X_B2B_ACCOUNT ='N'))
AND PROF.X_PAPER_BILL_FLG IS NOT NULL;
QUIT;
!

RTNCD=$?
if [[ ! 0 = $RTNCD ]] || [[ ! 0 = `grep -c 'ORA-' $EBPP_DATAFEED_DATAFILE` ]]
then
echo "ERROR: There were errors during EBPP data load process. Please check the log file: $EBPP_DATAFEED_LOGFILE" >> $EBPP_DATAFEED_LOGFILE
cat $EBPP_DATAFEED_DATAFILE >> $EBPP_DATAFEED_LOGFILE
echo "Removing data file $EBPP_DATAFEED_DATAFILE"
rm $EBPP_DATAFEED_DATAFILE
RTNCD=1
exit $EXIT_SQLPLUSERROR
fi

echo "main> INFO: Total Records written to eBPP data file : `wc -l $EBPP_DATAFEED_DATAFILE | tr -s ' '| cut -d ' ' -f2`" >> $EBPP_DATAFEED_LOGFILE
echo "main> INFO: `date`" >> $EBPP_DATAFEED_LOGFILE

###added the below 2 lines HD 1597462
echo "main> INFO: Completed sql query ready to send data files to valicert server- Return Code :" $RTNCD >> $EBPP_DATAFEED_LOGFILE
if [[ 0 = $RTNCD ]]
then

# upload data file into valicert server.
# Verify that Valicert files exist in the data directory

echo "main> INFO: Connecting to VALICERT and uploading data file" >> $EBPP_DATAFEED_LOGFILE

# export VALICERT_NOTIFICATION_FILE=$EBPP_DATAFEED_SCRIPTS/valiNotificati.txt
#
# Read the files and process
#
#for FILE in `ls $EBPP_DATAFEED_DATAFILE 2> /dev/null`
for FILE in `ls $EBPP_DATAFEED_DATA/EBPP_Users_Feed*.dat 2> /dev/null`
do
if [ $FILE=$EBPP_DATAFEED_DATAFILE ]
then

       echo "main&gt; INFO: Valicert Files: Name $FILE is being uploaded" &gt;&gt; $EBPP\_DATAFEED_LOGFILE
        $VAL\_ST_BIN/alltel-stc -f -g 5 -w 25 -u $FILE https://$VALICERT\_CHECKFREE\_USERNAME:$VALICERT\_CHECKFREE\_PASSWORD@$VALICERT_URL &gt;&gt; $EBPP\_DATAFEED_LOGFILE

       if [[ ! $? = 0 ]]
       then
            echo "FATAL: Error in uploading the file $FILE: \`date\` **" &gt;&gt; $EBPP\_DATAFEED_LOGFILE
            exit -1
       else
           print "main&gt; INFO: Successfully Completed uploading $FILE \`date '\+%m-%d-%Y %H:%M:%S'\`" &gt;&gt; $EBPP\_DATAFEED_LOGFILE
           tmpFN=$FILE.ctl
           EBPP\_DATAFEED_CONTROLFILE=$tmpFN
           wc -l $FILE | tr -s " "| cut -d" " -f2 &gt; $EBPP\_DATAFEED_CONTROLFILE
           $VAL\_ST_BIN/alltel-stc -f -g 5 -w 25 -u $EBPP\_DATAFEED_CONTROLFILE https://$VALICERT\_CHECKFREE\_USERNAME:$VALICERT\_CHECKFREE\_PASSWORD@$VALICERT_URL &gt;&gt; $EBPP\_DATAFEED_LOGFILE
       fi
   fi

done

#Create csv file eBPP_Last_FeedInfo.csv file with current system date

echo "main> INFO: Create eBPP_Last_FeedInfo.csv current date $CURRENT_FEED for Data Writer" >> $EBPP_DATAFEED_LOGFILE
echo "BUSOBJ=System Preferences" > $EBPP_LAST_DATAFEED
echo "BUSCOMP=System Preferences" >> $EBPP_LAST_DATAFEED
echo "FIELD_PROPERTIES=key," >> $EBPP_LAST_DATAFEED
echo "FIELD_NAMES=Name,Value" >> $EBPP_LAST_DATAFEED
echo "BEGIN" >> $EBPP_LAST_DATAFEED
echo "ALLTEL - EBPP Profile Feed,$CURRENT_FEED" >>$EBPP_LAST_DATAFEED

echo "main> INFO: Moving files to processed directory" >> $EBPP_DATAFEED_LOGFILE

mv $EBPP_DATAFEED_DATA/EBPP_Users_Feed*.* $EBPP_DATAFEED_PROCESSED

echo "main> INFO: Update ALLTEL - eBPP Profile Feed System Preferences with current date $CURRENT_FEED, Java Beans" >> $EBPP_DATAFEED_LOGFILE

java -classpath $EBPP_DATAFEED_CLASSPATH \
com.alltel.siebel.datawriter.DataWriter $EBPP_LAST_DATAFEED >> $EBPP_DATAFEED_LOGFILE

RTNCD=$?
if [ $RTNCD != 0 ]
then
echo "ERROR: Running Java Programming failed (returned $RTNCD)! terminating process!" >> $EBPP_DATAFEED_LOGFILE
echo "Please check the log file and classpath" >> $EBPP_DATAFEED_LOGFILE
exit 40
fi

exit $EXIT_SUCCESS
##added next 2 line for HD 1597462
else
echo "Process Exited with Error " >> $EBPP_DATAFEED_LOGFILE
exit $MINERRORLEVEL
fi

That depends on how the script works. Since it's a KSH file, I assume that you'll want to execute like this:

. batchuse/user.ksh

This way, if a variable is being set, it gets included into your session.

What part?

Also, please use the vB code tags so that we can read the code.

Hi please explain me the code mentioned below. i have enclosed tags. hope u will be able to read it..

umask 000
#
# Source in the home profile
#
if [ -f $HOME/.profile ]
then
. $HOME/.profile
else
echo "ERROR: Error sourcing $HOME/.profile !" >> $EBPP_DATAFEED_LOGFILE
exit 10
fi

TMP_OUTPUT_FILE="temp_log.tmp"
TMPBATCHPROC="temp_batch.tmp"

export CURRENT_FEED=`date +%Y-%m-%d`
#
# Source in the environment variables (if possible)
#
if [ -f ./eBPPDataFeed_env.rc ]
then
. ./eBPPDataFeed_env.rc
fi
#

# Set the error codes
#
. ./errorcodes.ksh
#
# Obtain the secure username and password (if it exists)
#
if [ -f "$BATCH_USER_DIR/batch_user.ksh" ]
then
TMPPWD=`pwd` # v1.1
cd $BATCH_USER_DIR # v1.1
. ./batch_user.ksh # v1.1
RTNCD=$? # v1.1
cd $TMPPWD # v1.1
if [ $RTNCD = 0 ]
then
export SIEBEL_USERNAME=$USERID
export SIEBEL_PASSWORD=$PASSWORD
else
exit $EXIT_BATCHUSER_FAILED
fi
else
echo "ERROR: batch_user.ksh does not exist, unable to source in variables" >> $EBPP_DATAFEED_LOGFILE
exit $EXIT_BATCHUSER_DOESNOTEXIST
fi
#
# Check if the Environment Variables are set, if not, exit -1
#
for i in SIEBEL_USERNAME SIEBEL_PASSWORD \
EBPP_DATAFEED_ROOT EBPP_DATAFEED_DATA EBPP_DATAFEED_SCRIPTS EBPP_DATAFEED_LOGS \
SIEBEL_DB_USERNAME SIEBEL_DB_PASSWORD SIEBEL_DB_ORACLESID SIEBEL_DB_TABLE_OWNER \
SIEBEL_ROOT EXIT_SUCCESS EXIT_ENV_MISSING EXIT_ENV_NOVALUE \
EXIT_SQLPLUSERROR EXIT_BATCHUSER_FAILED EXIT_BATCHUSER_DOESNOTEXIST MINERRORLEVEL
do

IS_SETF1=`env | grep "^$i=" | cut -d= -f1`
if [[ -z $IS_SETF1 ]]
then
echo "FATAL: Environment Variable $i is not set, terminating process" >> $EBPP_DATAFEED_LOGFILE
exit $EXIT_ENV_MISSING
fi

IS_SETF2=`env | grep "^$i=" | cut -d= -f2`
if [[ -z $IS_SETF2 ]]
then
echo "FATAL: Environment Variable $i has no value, terminating process" >> $EBPP_DATAFEED_LOGFILE
exit $EXIT_ENV_NOVALUE
fi
done
#
echo "main> INFO: Running eBPP Profile Data Feed Process with Table Owner $SIEBEL_DB_TABLE_OWNER @ `date`" >> $EBPP_DATAFEED_LOGFILE
# Let us know what we are doing
# Get the last feed date from system preferences and store in variable#

LAST_FEED=`sqlplus -S $SIEBEL_DB_USERNAME/$SIEBEL_DB_PASSWORD@$SIEBEL_DB_ORACLESID <<!
SET HEAD OFF
SET FEEDBACK OFF
SET PAGESIZE 0
SET LINESIZE 900
SELECT VAL FROM $SIEBEL_DB_TABLE_OWNER.S_SYS_PREF where SYS_PREF_CD = 'ALLTEL - EBPP Profile Feed';
QUIT;

!`

RTNCD=$?
if [[ ! 0 = $RTNCD ]] 
then
echo "ERROR: SQLPLUS Failed when searching for system preferences" >> $EBPP_DATAFEED_LOGFILE
cat $EBPP_DATAFEED_LOGFILE
exit $EXIT_SQLPLUSERROR
fi

Actually you added some color so it helps a little. The tags that you need to use use code and /code enclosed within brackets [ and ].

Since I'm not exactly certain which part of the code, I'll comment each line.

LAST_FEED=`sqlplus -S $SIEBEL_DB_USERNAME/$SIEBEL_DB_PASSWORD@$SIEBEL_DB_ORACLESID <<!  <== Starts a "here" documnet where all lines 
                                                                                            until the "!" is reached are executed in sqlplus
SET HEAD OFF                   <== Turns off Oracle column headings
SET FEEDBACK OFF               <== Causes sqlplus not to return any feedback from queries (e.g. number of rows deleted, inserted, etc)
SET PAGESIZE 0                 <== Cause all page breaks to be turned off and removes column headings
SET LINESIZE 900               <== Returns 900 character rows
SELECT VAL FROM $SIEBEL_DB_TABLE_OWNER.S_SYS_PREF where SYS_PREF_CD = 'ALLTEL - EBPP Profile Feed'; <== SQL statement
QUIT;                          <== Quit sqlplus

!`                             <== End of here document

RTNCD=$?                       <== return code from sqlplus, which isn't useful if your script runs while Oracle is offline (you'll get 0 then too)
if [[ ! 0 = $RTNCD ]]          <== Check to see if return code was not 0
then
echo "ERROR: SQLPLUS Failed when searching for system preferences" >> $EBPP_DATAFEED_LOGFILE  <== Logged message for SQL execution errors
cat $EBPP_DATAFEED_LOGFILE     <== Dump the log file
exit $EXIT_SQLPLUSERROR        <== Exit script with error code
fi

mark, i really appreciate your assiatance .. thank u very much for explaining me in detail.

the user name and passwords are stored in a seperate file to prevent easy access. they retrieve the username and pwd using the following code. i will be grateful if you could explain this a little bit. i m actually working hard on understanding, i m having difficulties as this is the first time i am ever working on unix.


umask 000
#
# Source in the home profile
#
if [ -f $HOME/.profile ]
then
. $HOME/.profile
else
echo "ERROR: Error sourcing $HOME/.profile !" >> $EBPP_DATAFEED_LOGFILE
exit 10
fi

TMP_OUTPUT_FILE="temp_log.tmp"
TMPBATCHPROC="temp_batch.tmp"

export CURRENT_FEED=`date +%Y-%m-%d`
#
# Source in the environment variables (if possible)
#
if [ -f ./eBPPDataFeed_env.rc ]
then
. ./eBPPDataFeed_env.rc
fi
#

# Set the error codes
#
. ./errorcodes.ksh
#
# Obtain the secure username and password (if it exists)
#
if [ -f "$BATCH_USER_DIR/batch_user.ksh" ]
then
TMPPWD=`pwd` # v1.1
cd $BATCH_USER_DIR # v1.1
. ./batch_user.ksh # v1.1
RTNCD=$? # v1.1
cd $TMPPWD # v1.1
if [ $RTNCD = 0 ]
then
export SIEBEL_USERNAME=$USERID
export SIEBEL_PASSWORD=$PASSWORD
else
exit $EXIT_BATCHUSER_FAILED
fi
else
echo "ERROR: batch_user.ksh does not exist, unable to source in variables" >> $EBPP_DATAFEED_LOGFILE
exit $EXIT_BATCHUSER_DOESNOTEXIST
fi
#
# Check if the Environment Variables are set, if not, exit -1
#
for i in SIEBEL_USERNAME SIEBEL_PASSWORD \
EBPP_DATAFEED_ROOT EBPP_DATAFEED_DATA EBPP_DATAFEED_SCRIPTS EBPP_DATAFEED_LOGS \
SIEBEL_DB_USERNAME SIEBEL_DB_PASSWORD SIEBEL_DB_ORACLESID SIEBEL_DB_TABLE_OWNER \
SIEBEL_ROOT EXIT_SUCCESS EXIT_ENV_MISSING EXIT_ENV_NOVALUE \
EXIT_SQLPLUSERROR EXIT_BATCHUSER_FAILED EXIT_BATCHUSER_DOESNOTEXIST MINERRORLEVEL
do

IS_SETF1=`env | grep "^$i=" | cut -d= -f1`
if [[ -z $IS_SETF1 ]]
then
echo "FATAL: Environment Variable $i is not set, terminating process" >> $EBPP_DATAFEED_LOGFILE
exit $EXIT_ENV_MISSING
fi

IS_SETF2=`env | grep "^$i=" | cut -d= -f2`
if [[ -z $IS_SETF2 ]]
then
echo "FATAL: Environment Variable $i has no value, terminating process" >> $EBPP_DATAFEED_LOGFILE
exit $EXIT_ENV_NOVALUE
fi
done

Set the default file permissions 
umask 000
#
# Source in the home profile
#
Set the session environment if the file .profile exists in your home directory; I assume this is run from cron 
if [ -f $HOME/.profile ]
then
. $HOME/.profile
else
echo "ERROR: Error sourcing $HOME/.profile !" >> $EBPP_DATAFEED_LOGFILE
exit 10
fi

Define temp variables 
TMP_OUTPUT_FILE="temp_log.tmp"
TMPBATCHPROC="temp_batch.tmp"

Define a variable with today's date 
export CURRENT_FEED=`date +%Y-%m-%d`

Add to the session environment some stuff in this .rc file if it exists 
#
# Source in the environment variables (if possible)
#
if [ -f ./eBPPDataFeed_env.rc ]
then
. ./eBPPDataFeed_env.rc
fi
#

Add more to the session's environment 
# Set the error codes
#
. ./errorcodes.ksh

Add more to the session's environment (username and password probably 
#
# Obtain the secure username and password (if it exists)
#
if [ -f "$BATCH_USER_DIR/batch_user.ksh" ]
then
TMPPWD=`pwd` # v1.1
cd $BATCH_USER_DIR # v1.1
. ./batch_user.ksh # v1.1
RTNCD=$? # v1.1
cd $TMPPWD # v1.1

If previous script return a 0 result, set some Seibel username and password variables; otherwise exit script 
if [ $RTNCD = 0 ]
then
export SIEBEL_USERNAME=$USERID
export SIEBEL_PASSWORD=$PASSWORD
else
exit $EXIT_BATCHUSER_FAILED
fi
else
echo "ERROR: batch_user.ksh does not exist, unable to source in variables" >> $EBPP_DATAFEED_LOGFILE
exit $EXIT_BATCHUSER_DOESNOTEXIST
fi
#
# Check if the Environment Variables are set, if not, exit -1
#
Loop through a list of keywords... 
for i in SIEBEL_USERNAME SIEBEL_PASSWORD \
EBPP_DATAFEED_ROOT EBPP_DATAFEED_DATA EBPP_DATAFEED_SCRIPTS EBPP_DATAFEED_LOGS \
SIEBEL_DB_USERNAME SIEBEL_DB_PASSWORD SIEBEL_DB_ORACLESID SIEBEL_DB_TABLE_OWNER \
SIEBEL_ROOT EXIT_SUCCESS EXIT_ENV_MISSING EXIT_ENV_NOVALUE \
EXIT_SQLPLUSERROR EXIT_BATCHUSER_FAILED EXIT_BATCHUSER_DOESNOTEXIST MINERRORLEVEL
do
Search through environment variables for the keyword 
IS_SETF1=`env | grep "^$i=" | cut -d= -f1`
If the search was unsuccessful, say so and exit script 
if [[ -z $IS_SETF1 ]]
then
echo "FATAL: Environment Variable $i is not set, terminating process" >> $EBPP_DATAFEED_LOGFILE
exit $EXIT_ENV_MISSING
fi
Same thing but this time, check the variable's value 
IS_SETF2=`env | grep "^$i=" | cut -d= -f2`
Exit script if variable wasn't set 
if [[ -z $IS_SETF2 ]]
then
echo "FATAL: Environment Variable $i has no value, terminating process" >> $EBPP_DATAFEED_LOGFILE
exit $EXIT_ENV_NOVALUE
fi
done