Chinaunix首页 | 论坛 | 博客
  • 博客访问: 226382
  • 博文数量: 57
  • 博客积分: 955
  • 博客等级: 准尉
  • 技术积分: 587
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-14 13:30
文章分类

全部博文(57)

文章存档

2012年(2)

2011年(55)

分类: LINUX

2011-05-06 21:19:58



本来想截图来着的,----太大了。截图不全,就复制粘贴吧,----各位多多指教
#!/bin/bash
# written by booduklee
#2011-05-05
# this program is to create dns_config_file
echo "-------------welcome to the cr_dns script--------- "
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
export PATH

# whether user is root

if echo $USER | grep '\' >> /dev/null;
then
echo "permmision passed"
else
exit 3
fi

# whether the scripts is running

if [ -f key_lock ];
then
echo "it has runned by others; please wait"
else
echo $$ > key_lock
fi


# whether the bind has installed

if grep '^named' /etc/passwd;
then
echo "you have installed the bind_dns"
else
echo " please install the bind ,then run the scripts"
fi

# ------------create named.conf-----------
config=/var/named/chroot/etc/named.conf
data=/var/named/chroot/var/named
export config
export data

# whether named.conf exists
if [ -f $config ];
then
echo "named.conf exists"
else
cp /usr/share/doc/bind-*/sample/etc/named.conf $config
sed '24,$d' $config
fi

# write zone
function cr_zone {
read -p "please input your zone_name:" zone;
cat >> $config << EOF
zone "$zone"  { type master; file "$zone.zone"; };
EOF
}
#######----------------     create ns_record ------
function name_zone {
touch $data/$zone.zone;
chown  named:named $data/$zone.zone;
read -p "please enter your ns:" ns;
if echo $ns | grep '.*\.$';
then echo " this ns is legal,please go on"
else
echo "this ns is invalid"
fi
read -p "please enter your admin_mail_address:" mail;

cat >> $data/$zone.zone << EOF
\$TTL  86400
@      IN     SOA     localhost.  $mail   (
                                            42   ; serial
                                            3H   ; refresh
                                            15M  ; retry
                                            1W   ; expiry
                                            1D ) ; minimum
      IN   NS   $ns
EOF
}
#------------------add A_record-----------------
function a_cord_zone {
i=1;
while [ $i -lt 2 ] ;
do
read -p "whether you want to create a_record (y|n):" a_ch;
case $a_ch in
y)
 read -p "please input your a_name:" a;
 read -p "please input your ip_address:" ip;
if echo $ip | egrep -x '([1-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|25[0-5])\.([1-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|25[0-5])\.([1-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|25[0-5])\.([1-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|25[0-5])' ;   #  to decide whether the ip_address is valid
then
echo "this ip_address is legal" >> /dev/null
else
echo "this ip_address id invalid"
exit 6;
fi
cat >> $data/$zone.zone << EOF
$a    IN  A   $ip
EOF
;;
n)
    i=$[ i+1 ];
    ;;
*)
   echo "INPUT ERROR, you can just enter (y|n)";
    exit 0;
   ;;
esac
done
}
while true;
do
read -p "do you want to create a new zone:(y|n)" choice

case $choice in
y)
 while true;
do
read -p "whther go on(y|n):" tuichu
case $tuichu in
y)
cr_zone;
name_zone;
a_cord_zone;
 ;;
*)
rm -rf key_lock;
exit 9;
;;
esac
done
;;
n)
   echo " will be quit"
    rm -rf key_lock
    exit 4
   ;;
*)
    echo "INPUT ERROR , you can just enter y|n "
    exit 0
    ;;
esac
done
rm -rf key_lock  #  delete the pid_lock
#-----------------it's over----------------------------------------------

阅读(1440) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~