user72055
user72055

Reputation: 489

Launch two xterm and ssh into servers automatically

I'm using the following bash script and it has a couple of issues:

  1. The second xterm doesn't launch until the first is killed
  2. I've got to kill each xterm launched with quit instead of simply $exit
  3. The bash terminal I run the script from is locked until both xterms have been killed
  4. I would like to change directories after launching xterm and ssh into server

    read -s -p "PW? " password
    
    xterm -bg red -fg yellow -hold -e sshpass -p $password ssh user@server1
    
    xterm -bg blue -fg yellow -hold -e sshpass -p $password ssh user@server2
    

Any help would be appreciated. Thanks.

The solutions provided allowed me to create the following that works perfectly:

xterm -bg red -fg yellow -e sshpass -p $password ssh -Y -t user@server1 'cd /home/user/work; $SHELL -i' &
xterm -bg blue -fg yellow -e sshpass -p $password ssh -Y -t user@server2 'cd /home/user/work/; $SHELL -i' &

Upvotes: 1

Views: 1927

Answers (1)

glenn jackman
glenn jackman

Reputation: 247012

Questions (1) and (3) are solved by launching the xterms in the background:

xterm -bg red  -fg yellow -hold -e sshpass -p $password ssh user@server1  &
xterm -bg blue -fg yellow -hold -e sshpass -p $password ssh user@server2  &

Question (4), you can do more interesting things with expect, but this should do (tested only with ssh, not with xterm and sshpass):

xterm -bg blue -fg yellow -hold -e sshpass -p $password ssh -t user@server2 'cd /var/log; $SHELL -i'  &

It assumes your SHELL understands -i to mean "an interactive shell".
Note the addition of the -t option to ssh.

Upvotes: 2

Related Questions