#!/usr/bin/expect
if { $argc != 2 } {
send_user "usage: expect ssh.exp ip\n"
exit
}
#define var
set ip [lindex $argv 0]
set password [lindex $argv 1]
spawn ssh-copy-id -i $ip
expect {
-timeout 2
"(yes/no)?" {send "yes\r";exp_continue}
"*password" {send "$password\r"}
timeout {puts "expect connect timeout,pls contact root;" return}
}
expect eof
exit -onexit {
send_user "root say good bye to you!\n"
}
原文地址:http://blog.51cto.com/yht1990/2151735
时间: 2024-10-24 04:14:05