模拟SHH 输入密码

#!/usr/bin/expect  
set timeout 30  
set passwderror 0
set passwd "password"

spawn ssh [email protected]  "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




你可能感兴趣的:(Linux)