expect script hangs while waiting for the flag...

I am writing a script to check whether the root password is set to a special string on some solaris servers.

Normally, the manually ssh login session is as below:

$ ssh root@host1
Password:
Last login: Wed Sep 16 13:53:28 2009 from 10.1.102.13
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
#

But the script hangs with below message:

$ ./ssh_check.exp
spawn ssh root@10.1.102.13
The authenticity of host '10.1.102.13 (10.1.102.13)' can't be established.
RSA key fingerprint is ae:f9:36:bc:dc:b9:33:4d:72:a2:d7:fb:87:c7:e4:fc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.1.102.13' (RSA) to the list of known hosts.
Password:
Last login: Tue Sep 15 18:40:29 2009 from 10.1.102.13

but it seems that the program keeps wiat the "#". But due to some reason, the sign just won't come out...

Below is the code of my script:

#!/bin/expect --

set user "root"
set password "xxxx"
set dead_list ""
set missed_list ""
set timeout 15
set missed 0
set dead 1
set done 1

set server_list {"host1", "host2"}

foreach server $server_list {
spawn ssh $user@$server
set done 1
while {$done} {
expect {
"yes/no" {
send "yes\n"
set dead 1
}
-re "(P|p)assword" {
if {$missed} {
send \003
lappend missed_list $server
set missed 0
set done 0
} else {
send "$password\n"
set missed 1
}
}
"#" {
send "exit\n"
set missed 0
set dead 1
set done 0
}
"Last" {
send \003
set missed 0
set dead 1
set done 0
}
timeout {
if {$dead} {
lappend dead_list $server
set missed 0
set dead 1
set done 0
}
send \003
}
}
}
wait
}

Thanks in advance

change your ssh command

from :
spawn ssh root@10.1.102.13

to:

spawn ssh -oStrictHostKeyChecking=no root@10.1.102.13

with this option, it will not ask to manually type "yes", when you ssh to a new host.

it works here, thx rdcwayx....

but the issue which blocks me is still unsolved....which the script just wait "#" when i run it...

---------- Post updated at 09:44 PM ---------- Previous update was at 02:19 AM ----------

Is there anyone who can provide some suggestion on this issue?

you need manually ssh to the server which has issue, and check which prompt you get.

If it is not #, you need adjust your expect script.

That's the part which confuses me...

Manually ssh the server
$ ssh root@host1
Password:
Last login: Wed Sep 16 13:53:28 2009 from 10.1.102.13
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
#

But the script hangs with below message:

$ ./ssh_check.exp
spawn ssh root@10.1.102.13
Password:
Last login: Tue Sep 15 18:40:29 2009 from 10.1.102.13

I just can not get why the "#" doesn't show up as it does in the munual way.

Comparing the output difference, it seems that there is a shell launched after the login, but "expect" does not get the output....