In the past, SCP files were all based on. Ssh.
However, using SCP in the script to copy files between machines becomes a problem.
The first method is CT.
The script is as follows:
#! /Usr/bin/CT-F
Spawn SCP 1 [email protected]:
Reset CT "* password :"
Send "your password \ r"
CT EOF
Of course, it's not just SCP, but other commands can also be automated using reverse CT.
Loop processing:
Spawn SCP 1 [email protected]:
For {set I 1 }{$ I <500} {incr I }{
Keep CT {"* password:" {send "Koven \ r "}
"* (Yes/no) *" {send "Yes \ r "}
}
}
Note that there is a space between braces.
The second method is to use the key file.
Assume that host a (192.168.100.3) is used to obtain the file of host B (192.168.100.4.
Run the following command on host a to generate a pair key:
Ssh-keygen-T RSA
When the prompt "Press ENTER" is displayed, the Public Key is saved to the. Ssh directory under the user directory. For example, root is stored in:
/Root/. Ssh/id_rsa.pub
Copy the id_rsa.pub file in the. Ssh directory to the ~ of host B ~ /. Ssh/directory, and renamed it authorized_keys,
Run the command in host a to establish trust with host B. For example, assume host B's IP address is 192.168.100.4 ):
SCP ~ /. Ssh/id_rsa.pub 192.168.100.4:/root/. Ssh/authorized_keys
The SCP and SSH commands can be used to obtain the files of host B without a password.
SSH 192.168.100.4 and press Enter.
Note: in fact, the id_rsa.pub content can be added to the authorized_keys of the other machine.
Bytes -----------------------------------------------------------------------------------------------------
#! /Usr/bin/CT-F
Set Password
Spawn SCP username @ target machine IP Address: Path of the copy file to store the local file
Set timeout 300
Login CT "username @ destination machine IP address's password:" # Note: The "username @ destination machine IP Address" here is consistent with the above
Set timeout 300
Send "$ password \ r"
Set timeout 300
Send "Exit \ r"
CT EOF
Appendix: SCP Parameters
-R: Copy directory
-C: compression allowed
A complete example
#! /Usr/bin/CT-F
Set Password 123456
# Download
Spawn SCP [email protected]:/root/a. wmv/home/yangyz/
Set timeout 300
Reset CT "[email protected]'s password :"
Set timeout 300
Send "$ password \ r"
Set timeout 300
Send "Exit \ r"
CT EOF
# Upload
Spawn SCP/home/yangyz/ABC. SQL [email protected]:/root/test. SQL
Set timeout 300
Reset CT "[email protected]'s password :"
Set timeout 300
Send "$ password \ r"
Set timeout 300
Send "Exit \ r"
CT EOF
########
PS: Always CT needs to be installed first
How to Use SCP to enter a password in the script