Skip to content

Instantly share code, notes, and snippets.

@is
Created October 7, 2012 14:48
Show Gist options
  • Save is/3848577 to your computer and use it in GitHub Desktop.
Save is/3848577 to your computer and use it in GitHub Desktop.
Increase bind zone serial by python script
#!/usr/bin/python
import os, sys
def fresh_serial(fn):
fin = file(fn, 'r')
lines = fin.readlines()
fin.close()
ols = []
for line in lines:
if line.find('__ZONE_SERIAL__') >= 0:
curstr = line.split()[0]
curo = line.find(curstr)
newstr = '%-8d' % (int(curstr) + 1)
oline = line[:curo] + newstr + line[curo + 8:]
line = oline
print 'zone %s: serial %s -> %d' % (fn, curstr, int(curstr) + 1)
ols.append(line)
fout = file(fn, 'w')
fout.write(''.join(ols))
fout.close()
if __name__ == '__main__':
fresh_serial(sys.argv[1])
# vim:ts=2 sts=2 ai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment