Remote SCP file by using reverse CT in shell script: Before using reverse CT, you need to install two RPM packages: # rpm-ihv centos/expect-5.43.0-5.1.i386.rpm
# Rpm-ihv centos/expect-devel-5.43.0-5.1.i386.rpm or yum directly download and install Yum install your CT-y script as follows:
#! /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 // set the timeout value here, in seconds. If the number of copied files is large and many times, this value should be increased.
Send "Exit \ r" Keep ct eof attachment: SCP Parameter
-R: Copy directory
-C: A complete example of allowing Compression
Expect_scp.exp
========================================================== ======================================
- #! /Usr/bin/CT-F
- # Author by Kevin
- # Date is 2011-11-14
- Set Password vcdog
- # Download local host
- Spawn SCP-R [email protected]. 168.1.107:/root/dba_tool/test/root/dba_tool/
- Set timeout 3
- CT {
- "Yes/No" {send "Yes \ r"; exp_continue}
- }
- Reset CT "[email protected]'s password :"
- Set timeout 3
- Send "$ password \ r" ---- or \ n
- Set timeout 300
- Send "Exit \ r"
- CT EOF
- # Upload remote host
- Spawn SCP-r/root/dba_tool/t.txt [email protected]. 168.1.107:/root/dba_tool/
- Set timeout 3
- CT {
- "Yes/No" {send "Yes \ r"; exp_continue}
- }
- Reset CT "[email protected]'s password :"
- Set timeout 3
- Send "$ password \ r"
- Set timeout 300
- Send "Exit \ r"
- CT EOF
========================================================== ======================================== Test Verification:
# Chmod + X./expect_scp.exp
# Reverse CT./expect_scp.expspawn SCP-R [email protected]:/root/dba_tool/test/root/dba_tool/
[Email protected]'s password:
Test 100% 12 0.0kb/s
Spawn SCP-r/root/dba_tool/t.txt [email protected]:/root/dba_tool/
[Email protected]'s password:
T.txt 100% 254 0.3kb/s local server :( 192.168.1.106) [[email protected] dba_tool] # ll/root/dba_tool/
Total 64
-RW-r -- 1 Root 548 Nov 14 expect_scp.exp
-RW-r -- 1 Root 12 nov 14 23:24 Test
-RW-r -- 1 Root 254 Nov 14 23:24 t.txt
Remote Server: (192.168.1.107)
[[Email protected] dba_tool] # ll/root/dba_tool/
Total 60
-RW-r -- 1 Root 12 nov 14 Test
-RW-r -- 1 Root 254 Nov 14 t.txt
Shell automatically log on to upload and download