Python modifies DNS slave configuration file information

Source: Internet
Author: User

#!/usr/bin/env pythonimport osimport time## #backup  int.junmm.comsource= '/var/named/chroot/ Var/named/slaves/int.junmm.com ' target_dir= '/mnt/int.junmm.com ' target=target_dir + time.strftime ('%Y% m%d%h%m%s ') + '. Zip ' zip_command= "zip -qr  '%s '  %s"  % (Target, ". Join (source)) If os.system (zip_command) ==0:    print  ' successful backup to ',targetelse:     print  ' backup failed! ' #replace  dove configjm_list = []jm_file = file (source) line_num=int (Len (jm_ File.readlines ()) jm_dd =  "jm_qe = " With open (source, "R")  as f:     lines = f.readlines ()      with open ("/mnt/ Int.junmm.com.one "," W ")  as f_w:        for line in  lines:             #if   "Dove" in line:    if line.split () [0].strip ()  == " dove ": jm_dd =  lines.index (line) lines[jm_dd] =  "dove                     A        192.168.53.249 "lines[jm_dd+1] = "                          A        192.168.53.250 "    if line.split () [0].strip ()  == " Es-query ": jm_ Qe = lines.index (line) lines[jm_qe] =  "es-query                     A        192.168.53.249 "lines[jm_qe+1] = "                          a        192.168.53.250 "With open (Source," W ")  as f_w_t:for i in lines:     i = i.strip (' \ n ')     f_w_t.write (i)     f_w_ T.write ("\ n") #restart  namedrestart_command =  "/etc/init.d/named restart" If os.system ( Restart_command) ==0:    print  ' Successful restart to ', Restart_commandelse:     print  ' restart failed! '

This article is from the "Xieping_linux" blog, make sure to keep this source http://xieping.blog.51cto.com/3715452/1951768

Python modifies DNS slave configuration file information

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.