#!/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"
}