写这个的时候因为绝对路径的问题老是出错呵呵,-----下边蓝色字体部分
#!/bin/bash
#written by booduklee
#2011-05-08
#this program is used to change the A_record
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
export PATH
echo "--------------welcome to change your A_record---------"
# whether the user is root
if echo $USER | grep '\' >> /dev/null;
then
echo "permmision passed"
else
exit 3
fi
# whether the scripts if running now
if [ -f key_lock ];
then
echo "it has runned by others; please wait"
exit 2
else
echo $$ > key_lock
fi
#define path
config=/var/named/chroot/var/named
export config
# create function --------------
function change_A {
read -p "please input which zone you want to change:" zone;
if ls $config | grep $zone.zone;
then
read -p "please input which A_record you want to change:" old_a
if grep ^$old_a $config/$zone.zone; then
read -p "please input the new A_record:" new_a
sed -i "s/^$old_a/$new_a/" $config/$zone.zone
else
echo "this A_record not find"
fi
else
echo "this zone not find"
fi
}
function add_A {
read -p "please input which zone you want to add A_record:" zone;
if ls $config | grep $zone;
then
read -p "please input your new record:" n_a;
read -p "plese input your ip_address:" ip;
cat >> $config/$zone.zone << EOF
$n_a IN A $ip
EOF
else
echo "this zone not find"
fi
}
function del_A {
read -p "please input which zone you want to delete A_record:" zone;
if ls $config | grep $zone;
then
read -p "please input which A_record you want to del:" d_a;
if grep ^$d_a $config/$zone.zone; then
sed -i "/^$d_a/d" $config/$zone.zone
else
echo "this A_record not find"
fi
else
echo "this zone not find"
fi
}
#------------------------------------------------apply funciton----------
while true;
do
read -p "please input your choice:(add|change|del|quit)" choice
case $choice in
add)
add_A;
;;
change)
change_A;
;;
del)
del_A;
;;
*)
rm -rf key_lock
exit 3;
;;
esac
done
rm -rf key_lock
#-----------------it's over------------------------
阅读(2183) | 评论(0) | 转发(0) |