Script to open multiple terminal tabs and run a script in each

I'm looking to have a script that would open multiple terminal tabs in mate-terminal and run a script in each. Thanks for any help!

1 Like

Hi :slight_smile:

Someone already asked something similar :

Tell me if it's what you want to do :slight_smile:

1 Like

Hi, no I didn't manage to find an answer on this forum nor the man page yet.

Basically I'm trying to do something like this:

I want to execute a script.sh that does this:
#!/bin/bash
mate-terminal --tab --tittle="first tab" -e "command 1 && command 2; command 3";
--tab --tittle="second tab" -e "command 1 && command 2; command 3";
--tab --tittle="third tab" -e "command 1 && command 2; command 3";

expected behavior:
--tab >> should open the new tab
--tittle >> title of the tab
-e >> commands to be executed in the new tab

I can't figure out where to put brackets and quotation marks.

with screen it would look like this:
#!/bin/bash
screen -d -m -S first bash -c 'command1 && command2'
screen -d -m -S second bash -c 'command1 && command2'
screen -d -m -S third bash -c 'command1 && command2'

Well, for starters the option is --title, not --tittle. Also each of those three lines should start with the command mate-terminal, and if you want them all to launch all at once, you need not semicolons at the end of each line, but single ampersands. That will put the first two commands in the background, allowing the shell to launch the other commands in parallel.

Furthermore, if you're going to run multiple commands in a chain in each terminal tab, you should run the bash shell on each command line; the terminal program itself is not a shell, so you need a shell to parse the double ampersand and stuff.

To sum it up, your script should look like:

#!/bin/bash

mate-terminal --tab --title="First tab" -e "bash -c 'command 1 && command 2; command 3'" &
mate-terminal --tab --title="Second tab" -e "bash -c 'command 1 && command 2; command 3'" &
mate-terminal --tab --title="Third tab" -e "bash -c 'command 1 && command 2; command 3'"

If you type that as presented, that should work. Tell us if it doesn't.

Sidenote, you probably want ";", not "&&".

Thank you,

if I do

mate-terminal --tab --title="1" -e "bash -c 'sleep 5s'"

it opens a new tab okay for 5 seconds and closes. But if I do anything else, such as

mate-terminal --tab --title="1" -e "bash -c 'echo Hello'"
or
mate-terminal --tab --title="1" -e "bash -c 'sleep 5s & echo Hello'"

it only opens and immediately closes the tab and it won't execute anything that's in -c

mate-terminal --tab --title="1" -e "bash -c 'sleep 5 && echo Hello'" &

will work :slight_smile:

Is this what you wanted to thieve ?

as in magpie :thinking:

achieve* sorry xD I have troubles to switch between US and FR keyboard

1 Like

I use a UK keyboard with compose key set to get FR characters to keep it simple and avoid such issues :wink:

Thanks for the advise :slight_smile: but obviously this was a OSI layout 8 - located between keyboard and the chair issue xD

Did you managed to have your target working ?

1 Like

Not sure what you are referring to...

What you have asked at the beginning :slight_smile:

@olek Must be the sun in France getting to your chair... that's not my post :innocent:

Hahahaha xD It will be more the rain xD

Sorry my friend ...

1 Like

No, the proper command is:

mate-terminal --tab --title="1" -e "bash -c 'echo Hello && sleep 5'" &

Otherwise, the tab will stay open for 5 seconds, then print the message, then immediately afterward close, so you can't see the message!

2 Likes

Okay thank you for that. It works for that limited example that I presented at the beginning but apparently doesn't work for what I'm trying to get to. It doesn't open a full terminal that would work the same way as if I opened it manually. It doesn't do cd and it doesn't work as a full terminal...

I'm trying to run multiple instances of chia plotter that would be staggered by half an hour. Instead of opening tabs manually I wanted the terminal to do it for me. It can be done with screen but I don't want to use screen.

This is what ultimately I'm trying to do...
!/bin/bash
#1
mate-terminal --tab --title="1" -e "bash -c 'cd /home/thomas/chia-blockchain && . ./activate && sleep 0h && chia plots create -k 32 -b 3600 -r 2 -u 128 -n 999 -t /home/thomas/nvme3.2 -d /home/thomas/6-16-WD/plots | tee /home/thomas/plotlogs/1.log'";
#2
mate-terminal --tab --title="2" -e "bash -c 'cd /home/thomas/chia-blockchain && . ./activate && sleep 0.5h && chia plots create -k 32 -b 3600 -r 2 -u 128 -n 999 -t /home/thomas/nvme3.2 -d /home/thomas/6-16-WD/plots | tee /home/thomas/plotlogs/2.log'";
#3
mate-terminal --tab --title="3" -e "bash -c 'cd /home/thomas/chia-blockchain && . ./activate && sleep 1h && chia plots create -k 32 -b 3600 -r 2 -u 128 -n 999 -t /home/thomas/nvme3.2 -d /home/thomas/6-16-WD/plots | tee /home/thomas/plotlogs/3.log'";

it can be done with screen like this...
!/bin/bash
screen -d -m -S chia1 bash -c 'cd /home/user/chia-blockchain && . ./activate && sleep 0h && chia plots create -k 32 -b 4000 -r 4 -u 128 -n 16 -t /mnt/ssd/temp1 -2 /mnt/ssd -d /mnt/hdd |tee /home/user/chialogs/chia1_1_.log'

screen -d -m -S chia2 bash -c 'cd /home/user/chia-blockchain && . ./activate && sleep 1h && chia plots create -k 32 -b 4000 -r 4 -u 128 -n 16 -t /mnt/ssd/temp2 -2 /mnt/ssd -d /mnt/hdd |tee /home/user/chialogs/chia2_1_.log'

screen -d -m -S chia3 bash -c 'cd /home/user/chia-blockchain && . ./activate && sleep 2h && chia plots create -k 32 -b 4000 -r 4 -u 128 -n 16 -t /mnt/ssd/temp3 -2 /mnt/ssd -d /mnt/hdd |tee /home/user/chialogs/chia3_1_.log'

Can the mate-terminal open a full fetched new tab that would work as a full terminal tab? Or what would be an alternative? Thanks a lot.

I don't see what you're talking about here. I ran:

mate-terminal --tab --title="1" -e "bash -c 'cd /bin && ./ls && sleep 1'"

...on my own system here, and it prints a listing of the /bin directory in a new terminal tab as expected. Even the cd command worked. What leads you to believe that you can't do a cd?

2 Likes

It works now. Brilliant thanks for help.

1 Like