Chinaunix
标题:
expect 脚本问题
[打印本页]
作者:
jiean
时间:
2009-09-23 14:26
标题:
expect 脚本问题
proc do_console_login {login pass} {
set timeout 5
set done 1
# set timeout_case 0
while { $done } {
expect {
"(yes/no)?" {
send "yes\n"
expect "assword:"
send "$pass\n"
incr done
send_user "Login Successfully...\n"
}
"*assword:" {
send "$pass\n"
incr done
send_user "Login Successfully...\n"
}
# timeout {
# switch -- $timeout_case {
# 0 { send "\n" }
# 1 {
# send_user "Send a return...\n"
# send "\n"
# }
# 2 {
# puts stderr "Login time out...\n"
# exit 1
# }
# }
# incr timeout_case
# }
# }
}
}
}
proc do_exec_cmd {} {
expect ":~>"
send "uname -a\n"
expect ":~>"
send "exit\n"
expect eof
}
if { $argc !=3 } {
puts stderr "Usage: command host-address username host-password\n"
exit 1
}
set host [ lindex $argv 0 ]
set name [ lindex $argv 1 ]
set password [ lindex $argv 2 ]
spawn ssh $name@$host
do_console_login $name $password
do_exec_cmd
close
exit 0
复制代码
这是一个远程登录到终端执行SHELL 的expect程序,不知道为什么提示proc do_console_login无法执行,请帮忙改下
如果我要是用expect 远程登录到服务器上,执行编译安装软件,是不是得把timeout设置的时间长一点啊,才能阻止超时问题
作者:
phoenixson
时间:
2009-09-23 23:37
yes/no "/"是不是需要写成\/
作者:
waker
时间:
2009-09-24 08:12
\n ==> \r
作者:
jiean
时间:
2009-09-24 14:21
还是不行提示第一个proc无法运行,括号处有问题
invalid command name "}"
while executing
"}"
作者:
cute_orange
时间:
2009-09-24 17:12
标题:
回复 #4 jiean 的帖子
多了个}
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2