linux - Run two shell script in parallel and capture their output -
i want have shell script, configure several things , call 2 other shell scripts. want these 2 scripts run in parallel , want able , print live output. here first script calls other two
#!/bin/bash #configure stuff $path/instance2_commands.sh $path/instance1_commands.sh
these 2 process trying deploy 2 different application , each of them took around 5 minute want run them in parallel , see live output know deploying tasks. possible?
running both scripts in parallel can this:
#!/bin/bash #configure stuff $path/instance2_commands.sh >instance2.out 2>&1 & $path/instance1_commands.sh >instance1.out 2>&1 & wait
notes:
wait
pauses until children,instance1
,instance2
, finish2>&1
on each line redirects error messages relevant output file&
@ end of line causes main script continue running after forking, thereby producing child executing line of script concurrently rest of main script- each script should send output separate file. sending both same file visually messy , impossible sort out when instances generate similar output messages.
- you may attempt read output files while scripts running reader, e.g.
less instance1.out
output may stuck in buffer , not up-to-date. fix that, programs have open stdout in line buffered or unbuffered mode. use-f
or>
refresh display.
example d article on apache spark , parallel processing on blog provides similar shell script calculating sums of series pi on cores, given c program calculating sum on 1 core. bit beyond scope of question, mention in case you'd see deeper example.
Comments
Post a Comment