#! /usr/bin/expect set ip [lindex $argv 0]; set username [lindex $argv 1]; set password [lindex $argv 2]; set key_init "*yes/no*" set key_password "[Pp]assword:" set timeout 30 set prompt "(#|%|\\$) $" spawn ssh ${username}@${ip} expect { "$key_init" { send "yes\r" expect "$key_password" { send "${password}\r" } } "$key_password" { send "${password}\r" } timeout { puts "Timed out during login"; exit 1 } } expect -re "$prompt" send "exit\r" expect eof { send_user "eof\r" }
时间: 2024-11-01 05:34:12