星期六, 十二月 23, 2006

TCL expect for ssh

在 shell script 中调用 expect 来进行批处理模式下的 ssh 连接可参考如下模式:
__expect__()  {
expect -c "spawn $1
set timeout 3600
expect {
-re \".*.*continue connecting (yes/no)?\" { send -- \"yes\r\" }
-re \".*password: \" { send -- \"$_pass\r\" }
timeout {
send_user \"timeout\n\"
stty echo
exp_continue
}
}
expect eof
wait \$spawn_id
close"
}

__expect__ "ssh $_user@$_host \"$COMMAND\""

没有评论: