#!/usr/bin/expect
set host_ip "192.168.243.128"
set root_pwd "root"
set done 0
set donewitheof 0
log_user 0
spawn ssh root@$host_ip "id mc"
while {!$done} {
expect {
eof {
set done 1
set donewitheof 1
}
-nocase -re "Permission denied*" {
exit 1
}
-nocase -re "password*" {
send "$root_pwd\r"
}
-nocase -re "Are you sure you want to continue connecting*" {
send "yes\r"
}
-nocase -re "\[\r\n\]+uid.+$" {
set fd [open mc_groups "w+"]
set result $expect_out(0,string)
set result2 [string trim $result "\r\n"]
puts $fd "$result2"
flush $fd
close $fd
}
}
}
|