The following script is designed using expect utility. Please note that in order to execute this script you will need to have expect utility present on the server.
The following is how the script goes:
Code:
#!/usr/bin/expect -f
# connect via scp
spawn scp /home/gagan/myfile.txt user@remotehost:/var/www/html/
#######################
expect {
-re ".*es.*o.*" {
exp_send "yes\r"
exp_continue
}
-re ".*sword.*" {
exp_send "PASSWORD\r"
}
}
interact
Please note that in the above script, you will have to replace PASSWORD, with the password for user on remotehost.