Created
October 20, 2012 09:37
-
-
Save Deltachaos/3922787 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Short hacked script to automatically increase | |
# the serial of a zonehead file for BIND9. The | |
# zonehead file has the following format. | |
# | |
# Examle zonehead file | |
# ==================== | |
# $TTL 86400 | |
# @ IN SOA ns1.xtain.net. postmaster.xtain.net. ( | |
# 2012131011 ; serial | |
# 14400 ; refresh | |
# 1800 ; retry | |
# 604800 ; expire | |
# 86400 ) ; minimum | |
# | |
# | |
# Lizenz: CC0 / Public Domain - http://creativecommons.org/publicdomain/zero/1.0/deed.de | |
if [ "$(id -u)" -gt 0 ]; then | |
echo "Only root can do this" > /dev/stderr | |
exit 255 | |
fi | |
ZONEHEADFILE="/dnszones/shared/zonehead.part" | |
ZONEHEAD=$(cat "${ZONEHEADFILE}") | |
NEWDATE=$(date +%Y%d%m) | |
BASEMATCH="^\([[:space:]]\+\)\([0-9]\{8\}\)\([0-9]\{2\}\)\([[:space:]]\+;[[:spac e:]]\+serial\)$" | |
CURRENTDATE=$(echo "${ZONEHEAD}" | sed -ne "s/${BASEMATCH}/\2/p") | |
CURRENTCOUNT=$(echo "${ZONEHEAD}" | sed -ne "s/${BASEMATCH}/\3/p" | sed 's/0*//' ) | |
echo "Old Zonehead:" | |
echo "${ZONEHEAD}" | |
echo "###############################" | |
if [ "${CURRENTDATE}" == "${NEWDATE}" ]; then | |
CURRENTCOUNT=$((${CURRENTCOUNT}+1)) | |
else | |
CURRENTCOUNT=1 | |
fi | |
echo "${ZONEHEAD}" | sed -e "s/${BASEMATCH}/\1${NEWDATE}$(printf '%02d' ${CURREN TCOUNT})\4/" > ${ZONEHEADFILE} | |
echo "New Zonehead:" | |
cat "${ZONEHEADFILE}" | |
echo "###############################" | |
/etc/rc.d/named restart | |
sleep 2 | |
/etc/rc.d/named restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment