Sponsored Content
Top Forums Shell Programming and Scripting Wait for one processes to complete in a shell script Post 302824741 by franksunnn on Friday 21st of June 2013 12:17:34 PM
Old 06-21-2013
Assuming that you have three scripts "a.sh" "b.sh" "c.sh" and there are three log file "a.log" "b.log" "c.log", and here is my opinion:
Execution of b.sh depends on whether the last successful execution of a.sh. If execution of a.sh fails, it's unnecessary to execute b.sh;
If you agree that, here is my main workflow:
1. print a flag into a.log representing successful execution of a.sh.
2. before execution of b.sh, check whether a.sh executed successfully last time by using the flag in a.log
3. if a.sh executed successfully, execute b.sh
Here is my scripts:
a.sh
Code:
#!/bin/bash
start_exec_time=$(date +%Y%m%d%H%M%S) #This is the exact time when script a.sh starts to execute.
echo "Start at:$start_exec_time"
i=0
while [ $i -lt 10 ]
do
        echo "The script a.sh is being executed"
        sleep 1
        i=$(expr $i + 1)
done
fini_exec_time=$(date +%Y%m%d%H%M%S)  #This is the exact time when script a.sh finishes  executing.
echo "Finish at:$fini_exec_time"

b.sh
Code:
#!/bin/bash
echo "Start to execute the script b.sh"
echo "The script b.sh is being executed"
echo "Finish executing the script b.sh"

c.sh
Code:
#!/bin/bash
i=0
while [ $i -lt 10 ]
do
        ./a >> a.log
        if tail -1 a.log | grep -q '^Finish'
        then
                cur_flag=$(tail -1 a.log | gawk -F: '{print $2}')
                if [ "x${pre_flag}" = "x${cur_flag}" ]
                then
                        echo "script b.sh is unnecessary to be executed."
                        exit
                else
                        ./b >> b.log
                fi
        fi
        pre_flag=$cur_flag
        i=$(expr $i + 1)
done
now_time=$(date +%Y%m%d%H%M%S)
echo "Finish at:$now_time" >> c.log
cp a.log a.log.$now_time
cp b.log b.log.$now_time
rm -rf a.log b.log

Hope to help you

Last edited by franksunnn; 06-21-2013 at 01:30 PM..
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
All times are GMT -4. The time now is 01:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy