1

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' &
user72055
  • 469
  • 1
  • 6
  • 15

1 Answers1

2

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.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • Note, you must quote your password everywhere: `"$password"` – glenn jackman Dec 19 '14 at 17:34
  • @glennjackman Didn't want to write a completely new answer for the last 25% when you already covered the first 75%... Feel free to add it to your answer if you want... – twalberg Dec 19 '14 at 20:13