Home > other >  bash scripts execution in different terminals
bash scripts execution in different terminals

Time:08-01

I have bash scripts, which I execute from new terminal every time I want to start my project

celery.sh

activate () {
     . /Users/oleg/Desktop/auth/venv/bin/activate
}
activate
cd projectname
celery -A projectname worker -l info

flower.sh

activate () {
     . /Users/oleg/Desktop/auth/venv/bin/activate
}
activate
cd projectname
celery -A projectname flower --port=5555

start.sh

activate () {
     . /Users/oleg/Desktop/auth/venv/bin/activate
}
activate
cd projectname
python manage.py runserver 0.0.0.0:8000

this scripts are used on my local machine, and i execute them with 3 different commands each command in new terminal

./celery.sh

./flower.sh

./start.sh

I found it boring, and redundant that i'm forced to open this 3 terminals each time.

My goal is to create one script ./ultimatestart.sh which will start all of this three scripts, each of which should be opened in its personal terminal

Answer update, thanks to Olaf Kock i found out the solution for my MacOs and zsh terminal

i have two options, first which will start these three scripts celery.sh, flower.sh, start.sh

osascript -e 'tell app "Terminal" to do script "cd /Users/oleg/Desktop/auth &&
./celery.sh"'
osascript -e 'tell app "Terminal" to do script "cd /Users/oleg/Desktop/auth &&
./start.sh"'
osascript -e 'tell app "Terminal" to do script "cd /Users/oleg/Desktop/auth &&
./flower.sh"'

i also found it redundant, because now, i have 4 scripts, and with this update, i can start all these 3 terminals from one script

ultimatestarter.sh

osascript -e 'tell app "Terminal" to do script "activate () { 
                  . /Users/oleg/Desktop/auth/venv/bin/activate
                  } 
activate 
cd /Users/oleg/Desktop/auth/projectname
celery -A projectname worker -l info"'

osascript -e 'tell app "Terminal" to do script "activate () { 
                  . /Users/oleg/Desktop/auth/venv/bin/activate
                  } 
activate 
cd /Users/oleg/Desktop/auth/projectname
celery -A projectname flower --port=5555"'

osascript -e 'tell app "Terminal" to do script "activate () { 
                  . /Users/oleg/Desktop/auth/venv/bin/activate
                  } 
activate 
cd /Users/oleg/Desktop/auth/projectname
python manage.py runserver 0.0.0.0:8000"'

CodePudding user response:

  1. figure out, which terminal you'd like to start (I'm using xterm as an example)
  2. check your terminal's man page for the actual command to start it with an argument (optionally: To stay open once the command finished)
  3. execute the commands in the background (&)

For xterm this might be something like

xterm -e /bin/bash -ls -c "./celery.sh" &
xterm -e /bin/bash -ls -c "./flower.sh" &
xterm -e /bin/bash -ls -c "./start.sh" &

Sprinkle in pause, if necessary.

  • Related