用expect实现的自动登录到多台服务器的shell脚本
用expect实现的自动登录到多台服务器的shell脚本
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:#!/usr/bin/expect-fsetipaddress[lindex$argv0]setpasswd[lindex...

复制代码 代码如下:

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

}

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新linuxshell学习
热门linuxshell学习
脚本专栏子分类