使用expect自动登录 公司有两重账户,可以使用expect自动登录,代码如下 ```python #!/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 "yes\r";exp_continue } "assword" { send "$password\r"} } expect "service" {send "su - bot\r"} expect "assword" {send "$bot_password\r";interact} expect eof ``` 来自 大脸猫 写于 2017-08-04 15:55 -- 更新于2020-10-19 13:06 -- 0 条评论