#!/usr/bin/python import commands,os,time curdate = time.strftime("%Y%m%d%H") # Just in case things blow up os.system("cp -Rp /var/named /var/named.backup") os.chdir("/var/named") files = commands.getoutput("ls *.db").split("\n") for file in files: domain = file.rstrip('.db') record = "\n%s. 14400 IN TXT \"v=spf1 a:host.victoryvision.com mx ip4:209.59.143.77 ~all exp=%s\"\n\n" %(domain, domain) f = open(file, 'a') f.write(record) f.close() # Now we need to update the serial numbers for file in files: cmd = "sed -i -e \"s/[0-9]\{10\}/%s/\" %s" %(curdate, file) os.system(cmd) os.system("service named restart") print "Done!"