linux shell

关注公众号 jb51net

关闭
首页 > 脚本专栏 > linux shell > 自动登录到多台服务器

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

作者:

自动登录到多台服务器的shell脚本,用expect来实现的一段代码,需要的朋友可以参考下
复制代码 代码如下:

#!/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" }
}
您可能感兴趣的文章:
阅读全文