Automate SCP command using Shell Script

Below shell script will automatically do the scp ( Secured Copy ) process with out asking the password from the user. Basically automating the secured copy command.

* We can put this script in cron job for daily download or uploads.

* Script automatically manages password entering.

* Login to the new server will popup the Secured Key window asking YES or NO. Script automatically do yes and will continue the copy process.

File Name: scp_dump.sh

*******************************************************************************************************************

#!/usr/bin/expect -f

# connect via scp
spawn scp "user@example.com:/home/santhosh/file.dmp" /u01/dumps/file.dmp
#######################
expect {
-re ".*es.*o.*" {
exp_send "yes\r"
exp_continue
}
-re ".*sword.*" {
exp_send "PASSWORD\r"
}
}
interact

*******************************************************************************************************************

Output: