Bash script to wait for gnome-terminal to finish before continuing script, only works for first instance of script

StackOverflow https://stackoverflow.com/questions/17822471

  •  04-06-2022
  •  | 
  •  

سؤال

I have a bash script that opens a new gnome terminal with two tabs that runs more scripts. After the scripts in the two tabs finishes, the main script in the parent terminal continues to run.

When I run multiple instances of this bash script, it no longer waits for the additional gnome-terminals to finish before continuing the parent terminal script.

How do I fix it so that the additional instances of the script runs just like the first one?

Here is the bash script that I'm running. I run additional instances of this by typing sh scriptname.sh in a new terminal.

    gnome-terminal --tab --command="expect launchneuron.exp" --tab --command="expect launchmpj.exp"
echo "Simulation Complete"
echo "Plotting Results"
expect -c "
set timeout -1
spawn ssh $username@server
expect \"password\"
send \"$password\r\"
expect \"$ \"
send \"qsub -I -q abc -A lc_tb -l nodes=1 -l walltime=24:00:00 -d .\r\"
expect \"$ \"   
send \"sh plotgraph.sh\r\" 
expect \"$ \" 
send \"exit\r\"
" 
هل كانت مفيدة؟

المحلول

#!/bin/bash
date
bash -c "sleep 7" &
bash -c "sleep 5" &
wait
date

As you can see while running this script, both sleep commands will run in parallel, but main thread stalls, while they are running.

Sat. Jule 27 01:11:49 2013
Sat. Jule 27 01:11:56 2013

Replace sleep 7 with expect launchneuron.exp

and sleep 5 with expect launchmpj.exp

and add your plot commands after calling "wait":

echo "Simulation Complete"
...(your code to plot results)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top