Reputation: 489
I'm using the following bash script and it has a couple of issues:
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
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