用expect实现的自动登录到多台服务器的shell脚本
时间:2021-03-20 10:00:29|栏目: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" }
}
上一篇:linux使用管道命令执行ps获取cpu与内存占用率
栏 目:Shell
本文标题:用expect实现的自动登录到多台服务器的shell脚本
本文地址:http://www.codeinn.net/misctech/84259.html






