Wait for one processes to complete in a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wait for one processes to complete in a shell script
# 1  
Old 06-19-2013
Wait for one processes to complete in a shell script

Let's say I start process A.sh, then start process B.sh. I call both of them in my C.sh
How can I make sure that B starts its execution only after A.sh finishes.
I have to do this in loop.Execution time of A.sh may vary everytime.
It is a parameterized script.
# 2  
Old 06-19-2013
Unless you run a.sh with a '&', it should wait for a.sh to complete to start b.sh. you may also give a sleep time after a.sh and b.sh just to be sure.

Post your script snippet for better answers.
# 3  
Old 06-19-2013
Quote:
Originally Posted by rajamadhavan
Unless you run a.sh with a '&', it should wait for a.sh to complete to start b.sh. you may also give a sleep time after a.sh and b.sh just to be sure.

Post your script snippet for better answers.
Code:
for i in `cat sql_output.txt`
do
echo "bip $i is running"
cd $SCRIPT_DIR
sh bip.sh 01 3 $i > /arbor/integ_fx/rahul_raj/itsr_5652/bip.txt
sleep 90
BILL_REF=`tail -2  /arbor/integ_fx/rahul_raj/itsr_5652/bip.txt | head -1 | cut -d  " " -f  6`
cd /arbor/integ_fx/xit_dev_CH/bin
ksh runXitInvoice_PROFORMA_integ  $BILL_REF 0 bp > /arbor/integ_fx/rahul_raj/itsr_5652/PROFORMA_integ.txt
done

I think bip.sh is designed to run in background.
Current workaround i am using is sleep but i want to avoid it.
Thanks
# 4  
Old 06-19-2013
This is the third thread with your identical problem. Please share bip.sh! In above code snippet, bip.sh DOES NOT RUN in background!
# 5  
Old 06-19-2013
Quote:
Originally Posted by RudiC
This is the third thread with your identical problem. Please share bip.sh! In above code snippet, bip.sh DOES NOT RUN in background!
Hi Rudi,
Just shared the BIP in my other post

---------- Post updated at 05:28 PM ---------- Previous update was at 12:21 PM ----------

Quote:
Originally Posted by RudiC
This is the third thread with your identical problem. Please share bip.sh! In above code snippet, bip.sh DOES NOT RUN in background!
Hi here is the content of bip

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 &

Moderator's Comments:
Mod Comment Please use CODE tags for multi-line code, input, and output samples instead of ICODE tags.

Last edited by Don Cragun; 06-20-2013 at 12:31 AM.. Reason: Changed ICODE tags to CODE tags.
# 6  
Old 06-19-2013
Write the entire part below in your c.sh. This should solve your problem. Small modifictions may be required depending upon necessity



function mySleep
{
ps -fu $LOGNAME|grep a.sh|grep -v grep 2>>/dev/null
if [ $? -ne 0 ]
then
echo "a.sh still running...."
echo "sleeping for 2 seconds!!!"
sleep 2
mySleep
}



a.sh
mySleep
b.sh
This User Gave Thanks to mritusmoi For This Post:
# 7  
Old 06-19-2013
Quote:
Originally Posted by mritusmoi
Write the entire part below in your c.sh. This should solve your problem. Small modifictions may be required depending upon necessity



function mySleep
{
ps -fu $LOGNAME|grep a.sh|grep -v grep 2>>/dev/null
if [ $? -ne 0 ]
then
echo "a.sh still running...."
echo "sleeping for 2 seconds!!!"
sleep 2
mySleep
}



a.sh
mySleep
b.sh

Thanks for the reply.

Can you explain what your code is doing.I am new to unix
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script parallel tasks and command to wait untill complete?

Hello, im having bash script with while *** command1 && command2 && command3 && done i want to ask how i can prevent overloading server, by waiting untill all commands complete? any low resources intensive command like "wait" - i dont know if exist? (2 Replies)
Discussion started by: postcd
2 Replies

2. Shell Programming and Scripting

[Solved] Help with shell Script ,wait for some files for some time??

Hi All, I have the requirement that ,i have to write a shell script that job has to wait for a 7 touch files created by another application for 4 hours, if i get all 7 touch files ,i have to send a mail that i jobs are completed, if if it is waiting for more than 4 hours i have to send a mail... (2 Replies)
Discussion started by: Pradeep Shetty
2 Replies

3. Shell Programming and Scripting

In Shell Script Does Second Command Wait For First Command To Complete

Hi All, I have a question related to Shell scripting. In my shell script, I have following two commands in sequence: sed 's/^/grep "^120" /g' $ORIGCHARGEDAMTLIST|sed "s;$;| cut -f$FIELD_NO1 -d '|' | awk '{ sum+=\$1} END {printf (\"%0.2f\\\n\", sum/100)}' >$TEMPFILE mv $TEMPFILE $ORIGFILE... (3 Replies)
Discussion started by: angshuman
3 Replies

4. Shell Programming and Scripting

calling a shell script in background and wait using "wait" in while loop

Hi, I am facing a strange issue, when i call a script from my while loop in background it doesnt go in background, despite the wait i put below the whil loop it goes forward even before the process put in background is completed. cat abc.txt | while read -u4 line do #if line contains #... (2 Replies)
Discussion started by: mihirvora16
2 Replies

5. UNIX for Dummies Questions & Answers

How do you wait for command substitution processes to complete?

When running a command using the >(cmd) syntax in bash how do you wait for the command to complete before moving on in your script? Here is a simple example: zcat largefile.gz | tee >(wc && echo “HELLO”) > /dev/null # I tried wait, here but it doesn't wait for the process in the subshell.... (8 Replies)
Discussion started by: mrvwman
8 Replies

6. Filesystems, Disks and Memory

hdparm + HDIO_DRIVE_CMD(null) (wait for flush complete) failed: Inappropriate ioctl

Hi All, Am finding performance of my SD card using hdparm. hdparm -tT /dev/BlockDev0 /dev/BlockDev0: Timing cached reads: 1118 MB in 2.00 seconds = 558.61 MB/sec HDIO_DRIVE_CMD(null) (wait for flush complete) failed: Inappropriate ioctl for device Timing buffered disk reads: 14... (0 Replies)
Discussion started by: amio
0 Replies

7. Shell Programming and Scripting

wait for 5 seconds in shell script

hi how can i wait for 5 seconds inside my shell script? 'wait 5' command doesnot seem to be working? (2 Replies)
Discussion started by: gopsman
2 Replies

8. Programming

Howto spawn multiple child processes and wait?

As far as I can tell, the bash wait command waits for a logical "AND" of all the child processes. Assuming I am coding in C: (1) What is the function I would use to create multiple bash child process running perl? (2) What is the function I would use to reinvent the bash wait command so I... (4 Replies)
Discussion started by: siegfried
4 Replies

9. Shell Programming and Scripting

Wait for Background Process to complete

I am attempting within a for-loop, to have my shell script (Solaris v8 ksh) wait until a copy file command to complete before continueing. The specific code is: for files in $(<inputfile.lst) do mv directory/$files directory/$files ksh -m -i bg %% wait $! done I am shaky on the... (3 Replies)
Discussion started by: gozer13
3 Replies

10. Shell Programming and Scripting

PERL: wait for process to complete

I'm using PERL on windows NT to try to run an extract of data. I have multiple zip files in multiple locations. I am extracting "*.t" from zip files and subsequently adding that file to one zip file so when the script is complete I should have one zip file with a whole bunch of ".t" files in it. ... (2 Replies)
Discussion started by: dangral
2 Replies
Login or Register to Ask a Question