Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
02-25-2011, 11:05 AM
|
#1
|
Member
Registered: Mar 2010
Posts: 202
Rep:
|
script for managing SOA serial in zone files
Here's a little tool that does this:
- without arguments, updates the SOA serial in a zonefile to the current date. If the date was already updated, just updates the revision number (incrementing up to 99, and then again 01). Uses RFC 1912* recommended format.
- with $1 == <two digit number>, auto updates (if necessary) just the date part and uses your provided revision number.
- with $1 == <eight digit number>, uses that as a date (no validation of any kind), and just auto update the revision number
- with $1 == <full serial>, will just replace whatever the serial is with the provided serial, without any validation
* YYYYMMDDRR (4-digit year, 2-digit month, 2-digit day of month, 2-digit revision number)
This script + keeping SOA/NS/MX/CNAME RRs in a common file $included from other files with $ORIGIN and A/PTR/TXT RRs, made everything way easier to manage, enabling me to script some zone switchers, automatic failover/redirection of DNS on WAN changes, etc, etc. I think this stuff might be cool to integrate with something like this script and make nice CLI toolset for bind. Looking forward to implement it.
Please report errors, etc. Hope you find it useful.
code in pastebin
Code:
#!/bin/bash
# globals-------------------------------------------------------------------
script_name="${0##*/}"
script_dir=$(readlink -f "${0%/*}")
script_version=1
# this can be modded to be supplied from command line
named_dir='/var/named'
serialfile="ufis-common.txt"
# main----------------------------------------------------------------------
[[ "$1" ]] && {
(( ${#1} == 10 )) && newserial=$1
(( ${#1} == 8 )) && date=$1
(( ${#1} == 2 )) && revision=$1
! [[ "$1" =~ ^[0-9]+$ ]] || [[ -z "$newserial$date$revision" ]] && echo "$script_name: ERROR: can't do anything with $1" && exit 1
}
curserial="$( sed -ne 's/^.*\([0-9]\{10\}\).*/\1/g; /^[0-9]*$/p' "$named_dir/$serialfile" )"
# if we haven't been passed a serial lets build one
[[ -z "$newserial" ]] && {
# if we don't have a date get current
[[ -z "$date" ]] && date="$(date +%Y%m%d)"
# if we don't have revision number get next from the current, if current=99 or date<>today it'll be "01"
[[ -z "$contador" ]] && {
revision="01"
(( ${curserial:0:8} == $date )) && {
revision=$( printf "%02d" $(( 10#${curserial:8:2}+1 )) )
(( 10#$revision == 100 )) && echo "$script_name: warning: revision counter looped to 01" && revision="01"
}
}
newserial=$date$revision
}
# replace the serial
# some sanity checks here won't hurt
# this is a minimal one
(( ${#newserial} == 10 )) && {
echo "$script_name: new serial number $newserial"
sed -i "s/\(^.*\)$curserial\(.*$\)/\1$newserial\2/" "$named_dir/$serialfile"
}
Last edited by Juako; 02-26-2011 at 09:59 PM.
Reason: spelling error in the code
|
|
|
02-26-2011, 04:26 AM
|
#2
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
The forum here really isn't the best place for things like this, they tend to sink without trace. But it's a useful script potentially. What use did you have for this in your practises? Personally I'd recommend just using nsupdate to manipulate the zone files, and then it will deal with incrementing the serial on your behalf. I don't really pay attention to what the serial is - date encodings etc... just as long as you are consistent in how you update the file, all slaves will be in line etc, and there's nothing to care about.
BTW, there's a syntax bug on line 17. Double negative.
Last edited by acid_kewpie; 02-26-2011 at 04:27 AM.
|
|
|
02-26-2011, 05:17 AM
|
#3
|
Member
Registered: Mar 2010
Posts: 202
Original Poster
Rep:
|
Well i guess as long it's indexed in some some search engine "someone" looking for this will get to find it :P, i'm a novice in bind and hadn't heard of nsupdate, i'm checking its man now and looks cool, will try it out. That said i got used to tune zone files by hand, and have some includes (as i mentioned in the OP) which really makes all this very easy.
I just have two direct zones and some reverse zones, don't know how my scheme would scale, ymmv i guess. My main use for the script is in other scripts that poll my router to check what WAN routes are active and if changes are to be made they bring up the relevant zone files, update the serial and restart bind.
Couldn't find the error you mention in line 17, it seems it's just a closing brace. Could you expand on that?
Code:
$ sed -n '17p' soa-update-serial
}
Last edited by Juako; 02-26-2011 at 05:39 AM.
|
|
|
02-26-2011, 05:40 AM
|
#4
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
You said 'can't do nothing'...double negative.
|
|
|
02-26-2011, 05:45 AM
|
#5
|
Member
Registered: Mar 2010
Posts: 202
Original Poster
Rep:
|
Ahh hahaha i see, so it's a spelling error, not a bug. Thanks for noticing, we do in spanish say it as a double negative, "no puedo hacer nada". Seems indeed not a valid construction in english.
Last edited by Juako; 02-26-2011 at 10:06 PM.
|
|
|
All times are GMT -5. The time now is 07:28 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|