Shell scripting issue-running the background script

I have written the below query to genrate a telephone.I am passing account number from oracle database.
I am calling 2 scripts which generate the bill

  1. bip.sh (it runs in the background)
    2.runXitInvoice_PROFORMA_integ

bip.sh generates a number which runXitInvoice_PROFORMA_integ
uses.How can i execute the bip.sh in foreground for every acocount number

#!/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
SCRIPT_DIR=/arbor/integ_fx/scripts; export SCRIPT_DIR

LOG_FILE=error.log; export LOG_FILE

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


echo "LOGGING STARTS $today"
echo
echo

### Credentials for SQLPLUS


### Credentials for SQLPLUS

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


### Connecting ORACLE

echo "SQLPLUS CONNECTION"

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

EOF


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


for i in `cat sql_output.txt`
do
cd $SCRIPT_DIR
sh bip.sh 01 3 $i > bip.txt
sleep 360
echo "bip $i is running"
BILL_REF=`tail -2  bip.txt | head -1 | cut -d  " " -f  3`
cd ../xit_dev_CH/bin
ksh runXitInvoice_PROFORMA_integ  $BILL_REF 0 bp
done

please post the contents of bip.sh ...

Not clear what you want to achieve. You say bip.sh runs in background but you want it to run in foreground? In your code snippet I can't see bip.sh in background; you run it in FG until it finishes, then wait 6 min (for what?), and then run runXitInvoice_PROFORMA_integ on the last two lines of the log file. Please explain in detail and with samples what you want.

Hi Rudi ,
Thanks for the reply..bip.sh is designed to run in background .It is parameterized
script. It takes an account number as an input.For every account number it generates an unique number which needs to passed to another script and execution time of each bip.sh $accoun_num is different.
So how can i make sure that runXitInvoice_PROFORMA_integ begins execution only after bip.sh $accoun_num is finished its execution.
currently i am using sleep 100 but it is not efficient.

Improve the bip.sh!
Remove & signs, so commands run in foreground.
In case the delays are caused by /dev/random, consider replacing it with /dev/urandom (faster but randomness is lower).

Hi german boy,
Can't change the bip.sh.It is a very critical script which generate the bill.client would not allow me to change it .
So i am looking for workaround.
Thanks.

Until we see bip.sh we can't help further. Again: there's no sign that bip.sh is running in background (as far as I can see).

Hi here is the content of bip

#!/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 &