给有需要的朋友
目标:新增 demo1.abc.com至 demo25.abc.com这25个子域,相关设定已经在/etc/named.conf修改,只需要添加相应的zone文件了,位置 /var/named/abc.com/目录下
#!/bin/bash
declare -i aaa //定义两个整型数,好进行数值运算(自增)
declare -i bbb
aaa=0
while (( aaa <= 2 )) //做十位数循环,
do
while (( bbb < 9 )) // 个位数循环
do
if (( aaa == 2 &&bbb >= 5 )) //如果是高于25就退出
then
exit;
else
bbb=bbb+1
echo $bbb
[ $((aaa == 0)) = 1 ] && dn=db.demo$bbb.abc.com||dn=db.demo$aaa$bbb.abc.com //文件名:如果十位为0避免出现 demo01的情况,而是demo1
# dn=db.demo$aaa$bbb.abc.com
[ $((aaa == 0)) = 1 ] && dd=demo$bbb.abc.com||dd=demo$aaa$bbb.abc.com //域名,不能加db.,不然会出错
filepath=/var/named/abc.com/$dn //定义存放路径
echo "$TTL 3600
@ IN SOA ns1.abc.com. postmaster.abc.com. (
2005060600 ; serial
10800 ; refresh
3600 ; retry
604800 ; expire
3600 ; minimum
)" >>$filepath
echo ";" >>$filepath
echo "; Nameserver(s) for the domain." >>$filepath
echo ";" >>$filepath
echo " IN MX 10 mail.c2.abc.com.
IN A 192.168.1.2
$dd. IN NS ns1.abc.com.
$dd. IN NS ns2.abc.com.
" >>$filepath
fi
done