对于获取多台server状态且不用交互须要用到expect,但有时候expect无法获取返回值。这里解释一下expect怎样获取返回值
expect -c "
spawn $1;
expect {
"(yes/no)?
" {send "yes
";expect "assword:";send "$2
"}
"assword:" {send $2
}
eof
}
expect eof
catch wait result;
exit [lindex $result 3]"
我们能够在脚本里面这样定义。注意最以下的result
这里须要加上转义字符$。否则会把$result解析成shell里面的变量,但这里面的$result是须要expect解析的。