我是靠谱客的博主 动人紫菜,这篇文章主要介绍用expect实现的自动登录到多台服务器的shell脚本,现在分享给大家,希望可以做个参考。

复制代码 代码如下:

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

最后

以上就是动人紫菜最近收集整理的关于用expect实现的自动登录到多台服务器的shell脚本的全部内容,更多相关用expect实现内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(232)

评论列表共有 0 条评论

立即
投稿
返回
顶部