Upload the backup SQL files from one server to the corporate local server but the company's local server did key verification, that is, to use key to log on to the local server, as well as the external network of the server did not do key verification, OK, then directly from that server to drag data to the local server bar.
The script is as follows:
VI Down.exp
The code is as follows |
Copy Code |
#!/usr/bin/expect-f Set Timeout-1 Set passwd your password. Spawn Scp-r-p18330 root@72.11.x.x:/root/newfile/*/root/bak/ Match_max 100000 Expect-exact "Password:" Send--"$PASSWDR" Expect EOF |
The following methods are implemented:
The code is as follows |
Copy Code |
chmod +x Down.exp Expect Down.exp |
This allows you to copy the backup data from the public network server to the local server without entering a password.
PS: To install expect
CentOS Direct Yum-y Install expect
In this based on I need today company requirements Both original weekly down data back, but also manually to down data is the latest backup on the server, OK, in order to meet this requirement, I made some changes in the original script.
Manual Down Data script:
The code is as follows |
Copy Code |
#!/usr/bin/expect-f Set Timeout-1 Set passwd passwd Spawn ssh-p18330 root@72.11.x.x Expect { "Yes/no" {send "YESR"; Exp_continue} "Password:" {send "$PASSWDR"} } Expect "*#*" {send "Sh/root/soft_shell/copy_newfile.shr"} Spawn Scp-r-p18330 root@72.11.x.x:/root/newfile/*/root/sqlbak/ Match_max 100000 Expect "*assword*" {send "$PASSWDR"} Expect EOF |
copy_newfile.sh Script content:
The code is as follows |
Copy Code |
#!/bin/bash location= "/root/sqlbak/" Newfile= "/root/newfile" Old_file= '/root/newfile ' Rm-f ${old_file}/* file=$ (Find $location-type f-mtime-1) CP $file $newfile |
Explanation: Let the script log on to the server first, execute the copy_newfile.sh script, filter out the latest backup, and then automatically down to the local.
It's easy. Minor installation expect, use the following command:
The code is as follows |
Copy Code |
Yum-y Install expect |
All right, that's it.