Rsync backup is very convenient. You only need to install it and do not need to configure anything. However, it takes a long time to get lazy. How can I use rsync without entering a password?
There are many methods on the Internet, and SSH-keygen is the most convenient. However, it seems inconvenient for me to use it. It seems that there is only one password configuration file. Look for other methods.
Keep CT, which needs to be installed. It is very convenient to install it on centos5.4.
Yum install expect
After installation, you can use which history CT to check if it is in/usr/bin/history CT. This is an interactive script. Automatic Interaction is supported. Okay!
In a simple example, synchronize the files under/tmp/123 with/tmp/123 on the 111.222.3.1 server (the remote server is synchronized locally)
#! /Bin/bash
CT-c"
Set timeout 1200;
Spawn/SCP. Sh # the program to be run, or the script
CT {
"* Yes/No *" {send "yesr"; exp_continue}
"* Password *" {send "111 @ 111r";} #111 @ 111 represents the password of the server 111.22.3.1
}
Ct eof ;"
Let's look at/SCP. Sh.
/Usr/bin/rsync-avzp-delete-e 'ssh-P 100'/tmp/12222/rsync-sl@111.22.3.1:/tmp/123
The SSH port is 12222. If not, change the SSH connection port to 10000 or above and change it to correct here.
Rsync-Sl this is the rsync authorized user. During addition, you can directly use useradd-G rsync-Sl to add it to the rsync group.
Check the permission of the/tmp/123 directory in 111.22.3.1. The permission must be rsync: rsync-Sl.
Note:
"* Password *" {send "111 @ 111r";} #111 @ 111 represents the password of the server 111.22.3.1
The password here, if there are some characters such as $, may be problematic, you need to escape. If your password is 123 $ ABC, you must enter
123u0024abc
Point escape:. ==> u002e
Escape of dollar signs: $ ==> u0024
Escape of the multiplication Symbol: ^ ==> u005e
Escape from the left braces: {==> u007b
Escape from left square brackets: [==> u005b
Escape of left parentheses :( ==> u0028
Escape of vertical bars: |=> u007c
Escape of right parentheses: ==> u0029
Asterisk escape: * ==> u002a
Escape of the plus sign: + ==> u002b
Escape question mark :? ==> U003f
Escape the backslash: ==> u005c