I need to write a script to remotely connect from home to my university server via ssh and then from the server terminal, ssh to a virtual machine to process some data. Is this possible?
This is what I have tried so far:
#!/usr/bin/expect
set login "myuser"
set addr "test.ac.uk"
set addr2 "t002"
set pw "mypassword"
spawn ssh -o StrictHostKeyChecking=no $login@$addr
expect "$login@$addr\'s password:"
send "$pw\r"
expect "#"
spawn ssh -o StrictHostKeyChecking=no $login@$addr2 -p 22
expect "$login@$addr2\'s password:"
send "$pw\r"
expect "#"
send "cd /developer\r"
interact
Error: ssh: connect to host t002 port 22: Connection refused
This is the way I'm currently logging in manually from home successfully:
~/Desktop # ssh host
prompt to enter password.
Once logged on successfully.
-bash-4.2$ ssh user@t001user@t002
prompt to enter password again.
EDIT: I updated the second ssh line as suggested by Mike.
From:
spawn ssh -o StrictHostKeyChecking=no $login@$addr2 -p 22
To:
send "ssh -o StrictHostKeyChecking=no $login@$addr2 -p 22\r"
Now the script returns access denied, but at the same time it does log me into the server but not the virtual machine.