spawn与except组合可达到远程登录设备执行命令的作用
下面是登录设备的一段代码
#!/usr/bin/expect -f
user=root
host=1.1.1.1
password=root
spawn $user@$host
set timeout 60
except {
"(yes/no)?" {
send "yes "
expect "*assword:*"
send "$password
"
}
"assword:" {
send "$password
"
} timeout {
exit
} eof{
exit
}
}