#!/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