Reputation: 33
#!/usr/bin/expect
spawn ssh [email protected] -o StrictHostKeyChecking=no
expect "5555:"
send "$password\n"
expect "% "
send "exit\n"
No matter what value wrote on expect "5555:" this command still working and I have ssh connection.
Upvotes: 2
Views: 1498
Reputation: 5211
You should set a timeout and an action upon the timeout:
#!/usr/bin/expect
set timeout 5
spawn ssh [email protected] -o StrictHostKeyChecking=no
expect {
"5555:" { }
timeout { exit 2 }
}
send "$password\n"
expect "% "
send "exit\n"
Some extra info: the default timeout is 10 seconds. While expect
ing something, if the pattern has not been seen after $timeout
seconds, the expect
command without a "timeout" pattern simply returns and the script continues.
Upvotes: 3