Automatic package download remote files

Source: Internet
Author: User

#!/usr/bin/env puthonimport pexpectimport sys# Define target host r_ip= "Ip_addrss" r_user= "USERNAME" r_passwd= " PASSWORD "#定义目标主机nginx日志文件target_file ="/path/to/nginx_access.log "#运行ssh命令child  = pexpect.spawn ('/usr/ Bin/ssh ',  [r_user+ ' @ ' +r_ip]) #输入输出写入日志文件fout  = file (' Mylog.txt ', ' W ') child.logfile =  Fouttry:    child.expect (' (? i) password ') #匹配password字符串, (? i) case insensitive      Child.sendline (R_PASSWD)     child.expect (' # ')     child.sendline (' Tar  -czf /path/to/nginx_access.tar.gz  ' +target_file) #打包日志文件     child.expect (' # ')     print child.before    child.sendline (' exit ')      fout.close () except eof:   #定义异常处理     print  "expect eof "except timeout:  #定义超时处理     print " Expect timeout "child =  Pexpect.spawn ('/usr/BIN/SCP ',  [r_user+ ' @ ' +r_ip+ ':/data/nginx_access.tar.gz ', ' Home ']) #scp命令拷贝文件fout  = file (' Mylog.txt ', ' a ') child.logfile = fouttry:    child.expect (' (? i) password ')      child.sendline (passwd)     child.expect (pexpect. EOF) except eof:    print  "expect eof" except timeout:     print  "Expect timeout"


Automatic package download remote files

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.