#!/usr/bin/expect -fset ipaddress [lindex $argv 0]set passwd [lindex $argv 1]set timeout 30spawn ssh ro
#!/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" }
}
--结束END--
本文标题: 用expect实现的自动登录到多台服务器的shell脚本
本文链接: https://www.lsjlt.com/news/18058.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-18
2024-04-17
2024-04-11
2024-04-08
2024-04-08
2024-04-03
2024-03-15
2024-03-15
2024-03-11
2024-03-08
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0