使用expect自动登录

2019-11-22 09:36:53 浏览数 (15)

公司有两重账户,可以使用expect自动登录,代码如下

代码语言:javascript复制
#!/usr/bin/expect -f
set ip [lindex $argv [expr $argc-1]]
set user yinzihao
set host $ip
set password pwd1
set bot_password pwd2
set timeout -1

spawn ssh $user@$host
expect {
    "es/no" { send "yesr";exp_continue }
    "assword" { send "$passwordr"}
}

expect "service" {send "su - botr"}
expect "assword" {send "$bot_passwordr";interact}

expect eof

0 人点赞