Proper Use of WAIT Command Within .ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Proper Use of WAIT Command Within .ksh
# 1  
Old 10-17-2018
Proper Use of WAIT Command Within .ksh

I am trying to write a korn shell script (Z.ksh) that will execute three other korn shell scripts within it. The three korn shell scripts (A.ksh,B.ksh,C.ksh) each execute a series of .sas programs. A.ksh, B.ksh, and C.ksh must each wait until the last .sas program within them executes and finishes before the shell script itself finishes. Once C.ksh executes all it's .sas programs and they finish, Z.ksh can finish.

I have provided pseudo code for Z.ksh below, but also could use some advice about how to code A.ksh, B.ksh. and C.ksh.

I look forward to your responses.

Thanks.


Code:
#!/usr/bin/ksh
cd /some/directory/containing/korn/shells/on/Linux
ksh A.ksh
wait
ksh B.ksh
wait
ksh C.ksh
wait

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 10-17-2018 at 01:53 PM.. Reason: Added CODE tags.
# 2  
Old 10-17-2018
Welcome to the forum.


wait waits for a shell's background processes ("jobs") to finish. None of your scripts is executed in background - unless we're talking of some code part within either, for which it would make more sense to wait within.
When executed in "normal" foreground mode, each script WILL execute the .sas commands in sequence AND exit only when all are finished.
# 3  
Old 10-17-2018
An example of how you'd use wait:

Code:
sleep 5 &
echo "Sleep is running in background"
wait
echo "Sleep has quit"

The ampersand causes sleep to run in the background, allowing the shell to continue and print the next statement. Then wait prevents the shell from continuing until sleep has finished.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Proper way to pipe into awk command

What is the proper way to run two commands together? For example, in the below I would like run a command in bold then pipe that output to awk to re-format it. Thank you :). bedtools nuc -fi /home/cmccabe/Desktop/bed/hg19.fa -bed /home/cmccabe/Desktop/bed/xgen_baits.bed >... (3 Replies)
Discussion started by: cmccabe
3 Replies

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

3. Shell Programming and Scripting

Wait command help

Hi, Is there any way to know the child process status as and when it finished. If i write like below nohup sh a1.sh & ### has sleep 20 ;echo a1.sh nohup sh a2.sh & ### has sleep 10 ;echo a2.sh nohup sh a3.sh & ### has sleep 5 ;echo a3.sh wait This will wait till a1.sh ,a2.sh a3.sh... (0 Replies)
Discussion started by: patrickk
0 Replies

4. Shell Programming and Scripting

Net::SSH::Perl->Execute any unix command & display the output in a proper form

Net::SSH::Perl ...... how to print the output in a proper format my $cmd = "ls -l"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("$cmd"); print $stdout; the script works fine, but i am unable to see the output... (2 Replies)
Discussion started by: gsprasanna
2 Replies

5. Shell Programming and Scripting

wait command

Hi all, I have never used the wait command before and want to know how it works. I basically need to run four sqlplus sessions in parallel as background processes and i am spooling the results obtained from the database into files.I need to wait for all the processes to finish and then make... (2 Replies)
Discussion started by: vinoo128
2 Replies

6. BSD

proper syntax of grep command

I'm learning UNIX on my mac (BSD), using a manual. I'm trying to figure out the grep command, and am getting something wrong. I've opened one of my files in NeoOffice and am looking for a string, the phrase 'I am writing.' I've been to some sites to get the proper syntax, and from what I can see... (5 Replies)
Discussion started by: Straitsfan
5 Replies

7. Shell Programming and Scripting

help in wait or sleep command

Hi All, I have a script which runs 3 scripts. The first script creates two files. The other two scripts should run only when the files are created. I tried the following for loop , but it is not working. Can someone please help me. while ; do # Sleep until file does exists/is created... (4 Replies)
Discussion started by: nua7
4 Replies

8. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies

9. Shell Programming and Scripting

Wait Command

Does anyone have an example of a korn shell scripts kicking of multiple background processes and then using the wait command to get the return code from those processes? I want to write a program that kicks off multiple Oracle procedures and then wait for the return code before I procede.... (1 Reply)
Discussion started by: lesstjm
1 Replies

10. Shell Programming and Scripting

Help with wait command

I have a script that runs numerous other scripts. I am using a wait command to try and get the calling script to wait for all process called to finish before proceeding. Issues How can I set wait to timeout IE a called program never terminates. Alternatively how can I check the called... (1 Reply)
Discussion started by: ultraman
1 Replies
Login or Register to Ask a Question