Running parallel process

i am having 4 process,have to run parallel and not after one by one.
sample1.sh
sample2.sh
sample3.sh
sample4.sh

Thanks in advance.

i

Try

sample1.sh &
sample2.sh &
sample3.sh &
sample4.sh &
wait

I hope that this helps
Robin
Liverpool/Blackburn
UK

do i have to write this in file or it can be run directly.
As i have to put output of each script in to single file
and what is the exact role of "wait" command as mentioned above

This could be either keyed on the command line or filed and run as a script. The wait will hold up further processing until all background tasks have completed.

Would you be wanting all the output into a single file from this run? If so, then save these in a file with a few adjustments:-

> output.file                  # Clear the output file first
sample1.sh >> output.file &    # Run sample1 and append output
sample2.sh >> output.file &    # Run sample1 and append output
sample3.sh >> output.file &    # Run sample1 and append output
sample4.sh >> output.file &    # Run sample1 and append output
wait

Be careful that you don't have any other background processes running for your session as you will wait for those too. of course, there is no way to know what order thse scripts will write their output, so you might have to consider that.

Robin
Liverpool/Blackburn
UK

i have tried this one

sample1.sh &
sample2.sh &
sample3.sh &

log_1 > new.txt
log_2 >> new.txt
log_3 >> new.txt 

but the second part is not working after the first process (3 scripts are finished)

plz suggest something

I have no idea what you're even trying to do there. What would you expect that to be doing?

RUN ALL THE FOUR PROCESS AFTER COMPLETING THAT COMBINE THE OUTPUT OF ALL THE FOUR SCRIPT INTO ONE FILE.

script1 > filea &
script2 > filea &
script3 > filea &
script4 > filed &
wait
cat filea fileb filec filed > bigfile

No need to shout.

I figured log_1, log_2, log_3, etc were scripts since you were obviously running them. Hence, mystified what you were trying to do.

could be like this:-

cat main.sh

{
sh test.sh > 1.log
sh test2.sh > 2.log
sh test3.sh > 3.log
sh test4.sh > 4.log

cat *.log > combine.log
}

then run sh main.sh... you could see all output combine in 1 file...

OR

cat main.sh
{
sh test.sh > 1.log
sh test2.sh >> 1.log
sh test3.sh >> 1.log
sh test4.sh >> 1.log
}

then run sh main.sh... you could see all output combine in 1 file...

but dear friends its not working

after the all scripts completed its not coming out of that script

means

test1.sh &
test2.sh &
test3.sh &


log_1 > new.txt
log_2 >> new.txt
log_3 >> new.txt 

its running all the script but its not executing the appending operation of log.

take one example.

#test3.sh

while [ $i le 20 ]
do
echo "$1"
i=`expr $i + 1`
done

output

1
2
3
4
5

the script is getting held at 5 its not operation after this stage as we have to append the logs of four scripts into one

If you have GNU Parallel GNU Parallel - GNU Project - Free Software Foundation installed you can do this:

parallel '{} >{.}.out' ::: sample*.sh

or:

seq 4 | parallel "sample{}.sh > {}.out"

You can install GNU Parallel simply by:

wget http://git.savannah.gnu.org/cgit/parallel.git/plain/src/parallel
    chmod 755 parallel
    cp parallel sem

Watch the intro videos for GNU Parallel to learn more: