由于在使用DNS管理后台之前DNS记录是手动去写入的,记录格式有点乱。
现在按格式整理DNS记录(A记录以及CNAME记录):
domain TTL type data
www.baidu.com 1800 A 127.0.0.1
#!/bin/bash filelist=`ls | grep "^named"` basedir=`pwd` resdir="$basedir"/dnsdata/ rm -rf "$resdir" mkdir "$resdir" for File in $filelist do workdir="work/`echo "$File" | sed s/named.//g`" rm -rf "$workdir" mkdir "$workdir" -p sed -n ‘1,8p‘ "$File" > "$workdir"/"$File".head sed -n ‘9,$p‘ "$File" > "$workdir"/"$File".last cd "$workdir" &> /dev/null egrep -v ‘^$|^;‘ "$File".last > "$File".data grep -wE "A" "$File".data | sed ‘s/IN//g‘ | sort | uniq | sort -rn | awk ‘ NF == 3 {print $1"\t1800\t"$2"\t"$3}‘ > "$File".A grep -wE "A" "$File".data | sed ‘s/IN//g‘ | sort | uniq | sort -rn | awk ‘ NF != 3 {print $1"\t1800\t"$3"\t"$4}‘ >> "$File".A grep -wE "NS" "$File".data | sed ‘s/IN//g‘ | sort | uniq | sort -rn > "$File".NS grep -wE "CNAME" "$File".data | sed ‘s/IN//g‘ | sort | uniq | sort -rn | awk ‘ NF == 3 {print $1"\t1800\t"$2"\t"$3}‘ > "$File".CNAME grep -wE "CNAME" "$File".data | sed ‘s/IN//g‘ | sort | uniq | sort -rn | awk ‘ NF != 3 {print $1"\t1800\t"$3"\t"$4}‘ >> "$File".CNAME cat "$File".head > "$File".res cat "$File".NS >> "$File".res cat "$File".A >> "$File".res cat "$File".CNAME >> "$File".res cp -a "$File".res "$resdir" cd - &> /dev/null rm -fr "$workdir" done
将以上脚本放到记录路径下执行即可,整理后的记录文件放在dnsdata中.
本文出自 “勿忘初心” 博客,请务必保留此出处http://winterysea.blog.51cto.com/9677346/1708247
原文地址:http://winterysea.blog.51cto.com/9677346/1708247