I need to login through ssh
twice with a script and can't get it to work. This is what I have in my script file:
#!/usr/bin/expect
set login "user"
set addr "address1"
set addr2 "address2"
set pw "password"
spawn ssh $login@$addr
expect "$login@$addr\'s password:"
send "$pw\r"
expect "$login@host:"
spawn ssh $addr2
expect "$login@$addr\'s password:"
send "$pw\r"
interact
but this fails with the error:
user@host:~$ ssh: Could not resolve hostname address2: Name or service not known
send: spawn id exp7 not open
while executing
"send "$pw\r""
If I change the line spawn ssh $addr2
with exec ssh $addr2
it fails with the error:
user@host:~$ ssh: Could not resolve hostname address2: Name or service not known
while executing
"exec ssh $addr2"
What do I need to change in order to make this work?