#!/bin/ksh # # This script's purpose is to create an alias aliases.nowhere.null zone # containing all aliases for all servers for the different domains. # # G. RYCKEBOER : 19-sep-03 # - revision #2 : 22-sep-03 # Add variables # - revision #3 : 07-oct-03 # Add better comments $server="ns.nowhere.null" $named_path="/var/named/primary" $aliaszone="aliases.nowhere.null $zonelist="$named_path/zones.list" # All initial zone files are suffixed by ".hosts". # create zone version/revision number rev=01 version_date=`date +"%Y%m%d"` if [ -f $named_path$aliaszone ] ; then # First, get old revision number for the zone file # split date and revision oldver=`grep "; serial" $named_path$aliaszone | tr -s " " | cut -d " " -f 2` oldrev=`echo $oldver | perl -pe 's/........(..)/$1/'` # compare current date and zone date [ ! "a$oldrev" = "a" ] && if [ $version_date = `echo $oldver | perl -pe 's/(........)../$1/'` ] ; then # ++ revision number for the day if [ $rev -le $oldrev ] ; then if [ $oldrev -ge 10 ] ; then # handle 2 digits rev=`expr $oldrev + 1` else rev="0`expr "$oldrev" + 1`" fi fi fi fi # Create SOA cat << EOF ;; Usage : /usr/local/bin/mkaliaszone > $named_path$aliaszone @ IN SOA $server. root.$server. ( $version_date$rev ; serial 10800 ; refresh every 3 hours 3600 ; retry every hours 604800 ; expire after a week 86400 ) ; minimum TTL of 1 day IN NS $server. ;; ;; Do not edit this file !!! ;; Please edit th refering primary zone ;; this zone is made user /usr/local/bin/mkaliaszone ;; to maintain an easy way to join all platform servers ;; EOF # For each zone referencd in zone.list, let's parse them and create aliases for i in `cat $zonelist` do cat $i | perl -pe " chomp; if (/([^\\. \\t]+)(\\..*)?[ \\t]+[Ii][nN][ \\t]+[aA][\\t ]+(.+)/) # Get direct field 'toto IN A ip_address' { \$_ = \"\$1\\tIN CNAME\\t\$1.${i%.hosts}.\\n\" } else { # catch the comments unless (/^[ \t]*;/) { \$_ = ''; } else { \$_ .=\"\\n\"; } }" done # OK. The zone file is now created. echo ";; Usage : /usr/local/bin/mkaliaszone > $named_path$aliaszone"