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

全部博文(57)

文章存档

2012年(2)

2011年(55)

分类: Python/Ruby

2011-05-08 22:04:23

写这个的时候因为绝对路径的问题老是出错呵呵,-----下边蓝色字体部分
#!/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) |
给主人留下些什么吧!~~