Rsync for Linux operations Automation scripts

Source: Internet
Author: User
Tags rsync

The rsync cause of Linux operations Automation scripts

Because you want to do the synchronization log script, considering that the machine is more, the back also to expand.

Recently I was learning python (a comparative dish).

Ideas

Composition: Configuration file + Execute script

After the script executes, it reads the contents of each field in the configuration file and assigns values to the corresponding variables in the Execute command.

Configuration file Format:

password file path; user name; IP; module name; target location path

Code:
#!/bin/env python
Import Time,os,datetimewith Open (' config/auto_rsync.conf','R', encoding='Utf-8') asF:file_info=f.readlines () Count=0Count1=1 forFile_useinchFile_info:file_use.strip (" ") iffile_use[0] =="#"or file_use[0] =="\ n": Continue Else: File_line= File_use.split (";") Count+=1 whileCount1 <=Count:pass,user,ip,mod_name,ddir= file_line[0],file_line[1],file_line[2],file_line[3],file_line[4] #print (pass,user,ip,mod_name,ddir) nowtime= Datetime.datetime.now (). Strftime ('%y-%m-%d_%h:%m:%s') Os.system ("/usr/bin/nohup/usr/bin/rsync-avzp--password-file=%s%[email protected]%s::%s%s >>/var/log/rsync_%s.log "%(pass,user,ip,mod_name,ddir,nowtime)) Count1+=1Time.sleep (1)

Rsync for Linux operations Automation scripts

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.