Editing the header of zone files
Joseph S D Yao
jsdy at center.osis.gov
Thu Jul 6 19:32:48 UTC 2006
On Thu, Jul 06, 2006 at 10:50:36AM -0400, Nick Allum wrote:
> Does anyone have a quick way for me to edit the header information on
> multiple zone files. I have to edit about 400 zones with new header
> informaion. There should be an easy way to get the new header info into
> the top of the 400 existing files, and then at least I can just delete
> the old info.
>
> Thanks
Do you mean a comment header or an SOA record? Either way, I would
suggest a shell script using 'ex' and a "here document".
In doit.ksh:
#!/bin/ksh
# The following is off the top of my head, debug before running!
if [ "0" = "$#" ]; then
echo "Syntax: $0 zone.file ..."
exit 1
fi
today=`date "+%Y%m%d"`
mod=00
backdir=back.`date "+%Y%m%d.%H%M%S"`
mkdir "$backdir"
for i in "$@"; do
case "$i" in
-[0-9])
mod=0`expr "X$i" : 'X-\([0-9]\)'`
continue
;;
-[0-9][0-9])
mod=`expr "X$i" : 'X-\([0-9][0-9]\)'`
continue
;;
*)
;;
esac
if [ ! -f "$i" ]; then
echo "${0}: No such file \"$i\"."
continue
fi
cp -p "$i" "$backdir/$i"
ex - "$i" << EndOfEdit
/^\([^;]*\)200[0-6][01][0-9][0-3][0-9][0-9][0-9]/s//\1${today}$mod/
wq!
EndOfEdit
done
Then run:
named$ doit.ksh zone.*
--
Joe Yao
-----------------------------------------------------------------------
This message is not an official statement of OSIS Center policies.
More information about the bind-users
mailing list