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' &
2
  • 1
    need more details for q4: you mean on the remote shell session, you want to cd to some dir and then continue in the interactive shell? Dec 19, 2014 at 16:55
  • Yes. I need to use those windows for the day.
    – user72055
    Dec 19, 2014 at 16:58

1 Answer 1

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.

2
  • Note, you must quote your password everywhere: "$password" Dec 19, 2014 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, 2014 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.