Using Expect Script
#!/usr/bin/expect
#Aayush Tuladhar
#Usage ./splunk_install.sh servername
#Setting Variable
set server [lrange $argv 0 0]
spawn scp file.txt splunk@$server:/home/asadmin/testfile.txt
expect {
-re "RSA key fingerprint" {send "yes\r"}
}
set pass "east"
expect {
-re "Password:" {send "$pass\r"}
}
expect eof