用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" }
} 相关推荐
bluecarrot 2020-08-19
luvzhan 2020-07-28
pimshell 2020-06-27
wiseMale 2020-06-01
SciRui 2020-05-06
BingGoGo技术 2020-03-03
gcong 2020-03-01
linuxhh 2020-02-15
86427019 2020-01-20
tvk 2020-01-09
quzhongwei 2020-01-06
风吹草动 2019-12-09
dmbjzhh 2019-11-08
onetozero 2019-11-08
supetan 2016-05-23
rickenwang 2019-11-03
beiya 2011-07-25