模拟SHH 输入密码

#!/usr/bin/expect set timeout 30 set passwderror 0 set passwd "password"spawn ssh root@127.0.0.1"rm -rf *"expect { "*assword:*" { if { $passwderror == 1 } { puts "passwd is error" exit 2 } set timeout 1000 set passwderror 1 send "$passwd\r" exp_continue } "*es/no)?*" { send "yes\r" exp_continue } timeout { puts "connect is timeout" exit 3 } }



需要expect的支持

sudo yum install expect





【模拟SHH 输入密码】

    推荐阅读