Results 1 to 7 of 7
  1. #1

    SOA increment script

    I use this:

    #! /bin/bash
    # <pattern> <search> <replace>
    for f in $1; do
    echo $f
    sed s/$2/$3/g $f >$f.tmp
    rm $f
    mv $f.tmp $f

    to update various files that have a series of the same datastring in them with a new datastring. It helps things a lot, even down to DNS zones.

    My question is, does anyone here know if it's possible to add to this script to increment the serial number in the process and if so, how?

    Server is running cpanel if it makes a difference.

    Thanks in advance.

  2. #2
    Anyone out there have any ideas on this? Getting ready to migrate a couple servers and it would come in handy.

  3. #3
    Join Date
    Jun 2003
    if your zone files look like this example

    $TTL 86400 ; one day

    @ IN SOA (
    2002061002 ; serial number YYMMDDNN
    28800 ; refresh 8 hours
    7200 ; retry 2 hours
    864000 ; expire 10 days
    86400 ) ; min ttl 1 day


    * IN A

    note ; serial number YYMMDDNN comment, its the "tag" on which it detects the serial number, so if your files do look different, it will need changes/will not work

    you might try this

    if [ -z $1 ] ; then
    echo "usage: $0 file"
    exit 1
    LINENR=`grep -n ".*;.*serial number YYMMDDNN$" $1 | cut -d: -f1`
    LINE=`grep ".*;.*serial number YYMMDDNN$" $1 | cut -d\; -f1 | awk {'print $1'}`
    LINES=`wc -l $1 | awk {'print $1'}`
    HEAD=`expr $LINENR - 1`
    TAIL=`expr $LINES - $LINENR`
    SERIAL=`expr $LINE + 1`
    head -n $HEAD $1
    echo -e "\t\t\t$SERIAL ; serial number YYMMDDNN"
    tail -n $TAIL $1

    it does autoincrement the serial number and output the resulting file, usage would be like "script file > output", you can script it into a loop to auto create file and rename them to proper names.
    if you want to use it, best test it, since i didnt, so dont blame me if it breaks something

  4. #4
    Thanks for the effort sehe. Unfortunately, it generates syntax errors.

  5. #5
    # - scripts             Copyright(c) 2003
    #                                       All rights Reserved.
    # [email protected]     
    # Unauthorized copying is prohibited
    #Version: 0.01
    use strict;
    use DNS::ZoneParse;
    #zone_path - Path to the folder that named zones are stored in, this is not recursive search.
    my $zone_path	= '/var/named/';
    #Increment - Leaving this blank will cause the serial to take on a YYYYMMDDRR format (per RFC1912 2.2).
    my $increment	= '';
    print "Zone Serial Incrementer\t\t\t\\n\n";
    print "!WARNING | make sure to make a backup of your $zone_path dir | WARNING!\n";
    print "!WARNING | press ctrl+c now to abort, you have 5 seconds | WARNING!\n\n";
    sleep 5;
    if (-e "/etc/rc.d/init.d/named") {
    	system("/etc/rc.d/init.d/named stop");
    } else {
    	print "You Should stop named if you have not done so\n";
    	sleep 5;
    print "Building array of Zones...";
    my @ZONES = readdir(ZONES);
    print "Complete\n\n";
    foreach(@ZONES) {
    	next unless /\.db$/;
    if( -e "/etc/rc.d/init.d/named") {
    	system("/etc/rc.d/init.d/named start");
    } else { 
    	print "You can now start/restart named\n";
    	sleep 5;
    sub updateserial() {
    	my($zonedb) = @_;
    	my $zonefile = DNS::ZoneParse->new("$zone_path/$zonedb");
    	my $soa         = $zonefile->soa();
    	print "Modifying $zonedb -> old serial($soa->{serial}) - newserial(".$zonefile->new_serial($increment).")\n";
    	rename "$zone_path/$zonedb", "$zone_path/$zonedb.bak";
    	open NEWZONE, ">$zone_path/$zonedb";
    	print NEWZONE $zonefile->output();
    	close NEWZONE;
    Like us on Facebook to qualify for discounts!
    Offering: | Internap FCP Bandwidth! | Rebootless Kernel Updates! | Magento Optimized Hosting | Wordpress Hosting |
    Services: | Managed Multiple Cores 64bit Servers | Server Management |

  6. #6
    Join Date
    Jun 2003
    perl -pi -e 's/(\d+)/$1+1/e if/serial/' zone.db
    This adds one to the serial number each time it is run and requires a format similar to the one that sehe posted. Back up your files. :)

  7. #7
    Join Date
    Jun 2003
    Originally posted by Gnomercy
    Thanks for the effort sehe. Unfortunately, it generates syntax errors.
    runs ok here, linux gentoo
    "usage: ./ file"

    anyway, best go for the perl script, it looks professional unlike my 2min bash script

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts