inside the mind of a linux admin

Mass updating zone file serial numbers with sed

If you’ve ever administered a DNS (name server), than you know that serial numbers mean a lot. But what happens when you have several [hundreds|thousands] of zone that you need to make a mass-change to. That’s easy enough, there’s tons of ways to do that with sed, awk, or simple tools like “replace”. However, once you’ve done the easy work, you still need to update all the serial numbers as well. Here’s how I saved myself hours of manual labor:

If you’re even reading this article, it’s expected that you at least know that a serial number is in the form YYYYMMDDNN where NN is the update number for that day. So the serial number from my post today would be 2011031900.

Now here’s how you tell sed what you want done (note, this formula assumes that your previous serial numbers were post-2000):

# sed -i ‘s/20[0-9][0-9]\{7\}/2011031900/g’ *.db

This says to replace any text starting with 20+[any two numbers 0-9] and followed by another 7 digits with the string: 2011031900

Problem solved, check out your zones now (provided they end in the standard format of domain.tld.db).

Related Posts

synergy: How to enable crypto (encryption) and generate SSL certificate

The newer Linux versions of the popular mouse/keyboard sharing application “synergy” now has built in encryption. Here’s how to configure it: Just simply passing the –enable-crypto flag on your synergy server without having a proper SSL certificate will result in the inability to connect to clients and generate an error message similar to this in […]

Read More

Change Number Pad Delete (dot) key from a comma in Ubuntu Linux

I recently purchased a new keyboard and updated to the latest Ubuntu, I’m also an avid user of the number pad for quick input when dealing with spreadsheets or accounting. I found that my num pad’s delete key (“.”) was outputting a comma (“,”) instead. Pretty annoying? I agree, but this can be very easily […]

Read More

1 Comment

  • Luís Miguel Sequeira on Wednesday, February 27, 2013

    Works like a charm, thanks for the snippet. You might need to add -E under FreeBSD 9.X to get sed to behave like the GNU sed.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.