cat > $TUNNEL_DIR/expect.ssh-keygen.exp << EOF #!/usr/bin/expect -f # TIMEOUT #set timeout -1 set timeout 20 # Login parameters set ip_address [lindex $argv 0] set key_path [lindex $argv 1] #set cmdfile [ open [lindex $argv 5] ] spawn ssh-keygen -C "$ip_address" expect { "*save the key" {send "$key_pathr";exp_continue} "*passphrase" {send "r";exp_continue} "Overwrite (y/n)?" {send "yr";exp_continue} } expect eof