Shell automatically log on to upload and download

Source: Internet
Author: User
Tags scp file

 

 

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
========================================================== ======================================
  1. #! /Usr/bin/CT-F
  2. # Author by Kevin
  3. # Date is 2011-11-14
  4. Set Password vcdog
  5. # Download local host
  6. Spawn SCP-R [email protected]. 168.1.107:/root/dba_tool/test/root/dba_tool/
  7. Set timeout 3
  8. CT {
  9. "Yes/No" {send "Yes \ r"; exp_continue}
  10. }
  11. Reset CT "[email protected]'s password :"
  12. Set timeout 3
  13. Send "$ password \ r" ---- or \ n
  14. Set timeout 300
  15. Send "Exit \ r"
  16. CT EOF
  17. # Upload remote host
  18. Spawn SCP-r/root/dba_tool/t.txt [email protected]. 168.1.107:/root/dba_tool/
  19. Set timeout 3
  20. CT {
  21. "Yes/No" {send "Yes \ r"; exp_continue}
  22. }
  23. Reset CT "[email protected]'s password :"
  24. Set timeout 3
  25. Send "$ password \ r"
  26. Set timeout 300
  27. Send "Exit \ r"
  28. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.