#!/usr/bin/expect

#This script use to init the server keys, it rewrite the known_hosts config file

#This script have 3 parameters
#remoteip: the ip of the remote server
#username: the name for logging in
#userpass: the password for logging in

set remoteip [lindex $argv 0]
set username [lindex $argv 1]
set userpass [lindex $argv 2]

set timeout 5

spawn sftp $username@$remoteip

expect "*(yes/no)?*"

send "yes\n"

expect "*password*"

send "$userpass\n"

expect "*sftp>*"

send "quit\n"

expect eof
exit

