Chinaunix
标题:
运行后自动登录到多台服务器上执行程序
[打印本页]
作者:
sjhf
时间:
2009-03-23 10:49
标题:
运行后自动登录到多台服务器上执行程序
#!/usr/bin/expect -f
set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]
set timeout 30
spawn ssh root@$ipaddress
#expect "yes/no"
#send "yes\r"
expect "password:"
send "$passwd\r"
expect "]*"
send "mkdir -p /tmp/haha/haha2\r"
send "exit\r"
***************
expect {
"(yes/no)?" {
send "yes\n"
}
"password:" {
....
}
判断语句
if {$havepass == 0} {
expect "password:" { send "$pw\n" }
}
或者:
expect {
"yes/no" { send "yes\r"; exp_continue}
"password:" { send "$passwd\r" }
}
本文来自ChinaUnix博客,如果查看原文请点:
http://blog.chinaunix.net/u3/93926/showart_1872452.html
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2