tags:

views:

1132

answers:

1

My expect code does this: It does a ssh connect to another machine, sends the password and then returns the hostname of that machine. I give a sample of my code below
#!/usr/bin/expect -f
set ipaddr [lrange $argv 0 0]
set password [lrange $argv 1 1]
set timeout -1
spawn ssh root@$ipaddr hostname
match_max 100000
expect "*assword:*"
send -- "$password\r"
expect eof

This code runs perfectly many times but intermittently, I get the following error
send: spawn id exp4 not open
while executing
"send -- "$password\r""

Why is this happening?

A: 

Figured out why. I had generated ssh keys and copied it on to the destination machine. So there was no "Password: " prompt. Hence before send could complete, the ssh connection had closed.

I deleted the ssh keys from the destination machine and ran the script again and observed no issues

Ninja