您的位置:首页 > 运维架构 > Shell

用expect实现的自动登录到多台服务器的shell脚本

2013-02-25 00:00 2536 查看
#!/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 "yesr"
expect "password:"
send "$passwdr"
expect "]*"
send "mkdir -p /tmp/haha/haha2r"
send "exitr"

***************
expect {
"(yes/no)?" {
     send "yesn"
  }
"password:" {
   ....
}
判断语句
if {$havepass == 0} {
  expect "password:" { send "$pwn" }
}

或者:

expect {
"yes/no" { send "yesr"; exp_continue}
"password:" { send "$passwdr" }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: