当前位置: 移动技术网 > 网络运营>服务器>Linux > 用expect实现的自动登录到多台服务器的shell脚本

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

2017年12月12日  | 移动技术网网络运营  | 我要评论
复制代码 代码如下:

#!/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" }
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网