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