June 15

Linux: How to open multiple xterm windows while running a command in bash

My goal was to ssh to several servers at the same time. I wanted to open a new terminal for each connection. Then within the terminal, run a separate bash session launching my ssh connection. You have to launch within bash if you want to be able to continue using the terminal session after you exit your ssh session. I also wanted each terminal window to open at a different location on my screen,

The code below does the following
1. Generates six random horizontal numbers
2. Generates six random vertical numbers
3. starts each xterm application at random location, launching the command inside of a bash shell.

#!/bin/bash
data=($( shuf -i 75-1000 -n 6))
data2=($( shuf -i 75-450 -n 6))
#echo ${data[1]}
#echo ${data[2]}
xterm -geometry 150×32+${data[1]}+${data2[1]} -e bash -c ‘command; bash’ &
xterm -geometry 150×32+${data[2]}+${data2[2]} -e bash -c ‘command; bash’ &
xterm -geometry 150×32+${data[3]}+${data2[3]} -e bash -c ‘command; bash’ &
xterm -geometry 150×32+${data[4]}+${data2[4]} -e bash -c ‘command; bash’ &
xterm -geometry 150×32+${data[5]}+${data2[5]} -e bash -c ‘command; bash’ &
xterm -geometry 150×32+${data[6]}+${data2[6]} -e bash -c ‘command; bash’ &

By: nighthawk


Copyright 2021. All rights reserved.

Posted June 15, 2016 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. Securely email me using - PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B