Help with make sure shell script execute instruction in flow


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with make sure shell script execute instruction in flow
# 1  
Old 03-23-2011
Help with make sure shell script execute instruction in flow

Hi,

I want to write a shell script to make sure all the instruction is executive in flow.
eg.
I want my shell script to run finish this two progress first:
Code:
./program input_file_1.txt > input_file_1.txt.out &
./program input_file_2.txt > input_file_2.txt.out &

After then, only run the following command by using the output result from the above progress:
Code:
cat *.txt.out > input_file.final

Below is the content of the shell script that I wrote:
Code:
#!/bin/sh
./program input_file_1.txt > input_file_1.txt.out &
./program input_file_2.txt > input_file_2.txt.out &
cat *.txt.out > input_file.final

Unfortunately, when I running the shell script above. It will automatic execute the "cat *.txt.out > input_file.final". Even though my "./program input_file_X.txt > input_file_X.txt.out &" is still running. End up, my "input_file.final" is empty since the first two progress is still running and without produce any output file yet Smilie

Does anybody got any idea how to make sure the above shell script will start running "cat *.txt.out > input_file.final" only when the first two progress is run finish.

Thanks for any advice.
# 2  
Old 03-23-2011
You have not said what shell you are using but all modern shells have a wait builtin which will do what you want.

Here is the relevant section from the bash manpage.
Quote:
wait [n]
Wait for the specified process and return its ter-
mination status. n may be a process ID or a job
specification; if a job spec is given, all pro-
cesses in that job's pipeline are waited for. If n
is not given, all currently active child processes
are waited for, and the return status is zero. If
n specifies a non-existent process or job, the
return status is 127. Otherwise, the return status
is the exit status of the last process or job
waited for.
This User Gave Thanks to fpmurphy For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Access a complete flow with CURL + bash shell

Hello Experts , I have an use case which needed your help . I have been using google for 2 days buy couldn`t succed , i believe i can get the help here. Here is my use case to run on bash shell 1. Access an URL -- in script , it will be mentioned as inputURL 2. Once i accessed the URL... (5 Replies)
Discussion started by: radha254
5 Replies

2. Shell Programming and Scripting

Access a complete flow with CURL + bash shell

Hello Experts , I have an use case which needed your help . I have been using google for 2 days buy couldn`t succed , i believe i can get the help here. Here is my use case to run on bash shell 1. Access an URL -- in script , it will be mentioned as inputURL 2. Once i accessed the URL... (1 Reply)
Discussion started by: radha254
1 Replies

3. Shell Programming and Scripting

Batch script to execute shell script in UNIX server

Hi team, My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server. I have completed the first part i.e From windows to using to unix server with the help of psftp.exe code: psftp user@host -pw password <... (1 Reply)
Discussion started by: bhupeshchavan
1 Replies

4. Shell Programming and Scripting

Dos batch script to execute unix shell script

Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh. Thanks in advance (2 Replies)
Discussion started by: Shri123
2 Replies

5. Shell Programming and Scripting

Continue an instruction on more than one line in a script shell ?

Hello, I have a very long instruction to write, but, for lisibility reasons, I would like to cut it on more than one line and comment each lines. is it possible ? thanks :b: (1 Reply)
Discussion started by: shadok
1 Replies

6. UNIX for Dummies Questions & Answers

can't execute a shell script

Hi all, As i want to know how the shell command "nohup" worked.I logged in as the user named vincent through Gnome.Then i press ctrl+atl+F1 changed into a console and logged in as another user named kinsley.The user "kinsley" is added by me with "useradd",and now there's no HOME directory for... (6 Replies)
Discussion started by: homeboy
6 Replies

7. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

8. Shell Programming and Scripting

Execute unix shell script to text file using the script

Hi all, I am beginner in UNIX...I want to use unix shell script to create text.file...I know how to use using by command...can anybody tell me for the script? Thanks i changed the threads title from "tex file" to "text file", because "tex" would probably be misunderstood as reference to... (4 Replies)
Discussion started by: mastercar
4 Replies

9. Shell Programming and Scripting

Is there a way to make bash [or another shell] use all CPU cores to execute a single script?

I wrote a very simple script that matches combinations of alphabetic characters (1-5). I want to use it to test CPU speeds of different hardware/platforms. The problem is that on multi-core/processor systems, only one CPU is being utilized to execute the script. Is there a way to change that?... (16 Replies)
Discussion started by: ph0enix
16 Replies

10. Shell Programming and Scripting

Help need to make a shell script run for ffmpeg vhook watermaking in shell

i have a small problem getting a batxh shell script to run in shell this is the code the problem seems to be centered around the ffmpeg command, something maybe to do with the ' ' wrapping around the vhook part command this is a strange problem , if i take the ffmpeg command and... (1 Reply)
Discussion started by: wingchun22
1 Replies
Login or Register to Ask a Question