- 论坛徽章:
- 1
|
[原創] 簡單建立 dns 的 shell script
更新:
# 2) 2003-12-06 v0.2 by netman
# * improve options selection
# 3) 2003-12-06 v0.3 by netman
# * improve name server hostname determination
download:
http://www.study-area.org/linux/src/sample_dns.sh.tgz
diff 結果(v0.1 - v0.3):
- 66,7c6,7
- < # date: 2003-12-06
- < # version: v0.3
- ---
- >; # date: 2003-12-05
- >; # version: v.0.1
- 32c32
- < # 1) 2003-12-05 v0.1 by netman
- ---
- >; # 1) 2003-12-05 v0.01 by netman
- 34,37d33
- < # 2) 2003-12-06 v0.2 by netman
- < # * improve options selection
- < # 3) 2003-12-06 v0.3 by netman
- < # * improve name server hostname determination
- 39,43c35
- <
- < interact=
- < to_file=
- < backup=
- < update=
- ---
- >; options=hrstbf
- 48a41,43
- >; to_file=
- >; backup=
- >; update=
- 57d51
- < ns_host=$(hostname -s).$fwd_zone
- 66,69d59
- < echo "Usage:"
- < echo -e "\t${0##*/} [-h]"
- < echo -en "\t${0##*/} [-g|-t] [-u] [-b] [-i|"
- < echo "[-f fwd_zone] [-r rev_zone] [-n name_server]]"
- 72,76c62,63
- < echo -e "\t-g\trun the script"
- < echo -e "\t-i\tspecify own names interactively"
- < echo -e "\t-f\tname of forward zone"
- < echo -e "\t-r\tname of reverse zone"
- < echo -e "\t-n\tname of name-server"
- ---
- >; echo -e "\t-r\trun the script with default values"
- >; echo -e "\t-s\tspecify your own zone names"
- 78d64
- < echo -e "\t-u\tforce update db(s)"
- 79a66
- >; echo -e "\t-f\tforce update db(s)"
- 81,82c68
- < echo -e "\t# $0 -tu"
- < echo -e "\t# $0 -g -f test.cxm -r 3.2.1.in-addr.arpa -n ns.test.cxm"
- ---
- >; echo -e "\troot_shell# $0 -tu"
- 103c89
- < [ $# -eq 0 ] && {
- ---
- >; echo $@ | grep -q "[^$options-]" || [ $# -eq 0 ] && {
- 105c91
- < echo "${0##*/}: Error: missing argument."
- ---
- >; echo "${0##*/}: missing argument or invalid options."
- 112c98
- < echo "(press Enter for '$2', or press 'n' for none): "
- ---
- >; echo "(or press Enter for none): "
- 117c103
- < get_zone $1 $2
- ---
- >; get_zone $1
- 119,123d104
- < if [ -z "$z_name" ]; then
- < z_name=$2
- < elif [ "$z_name" = "n" ]; then
- < z_name=
- < fi
- 126,127c107,108
- < function run_intact {
- < get_zone forward $fwd_zone
- ---
- >; function run_spec {
- >; get_zone forward
- 129c110
- < get_zone reverse $rev_zone
- ---
- >; get_zone reverse
- 133,135c114,115
- < echo "(or press Enter for system defaults '$ns_host'): "
- < read _ns_host
- < ns_host=${_ns_host:-$ns_host}
- ---
- >; echo "(or press Enter for system defaults): "
- >; read ns_host
- 293c273
- < echo "1) delete '$fwd_zone' & '$rev_zone' sections from $named_conf."
- ---
- >; echo "1) delete '$zone' sections from $named_conf."
- 295c275
- < echo "2) run '${0##*/} -u' to override db files in $db_dir."
- ---
- >; echo "2) run '${0##*/} -f' to override db files in $db_dir."
- 306,308c286
- < echo
- < echo "Content will be written to $named_conf :"
- < echo "----start-------------------------------------"
- ---
- >; echo "---->; Content will be written to $named_conf :"
- 317,319d294
- < [ "$to_file" ] && {
- < echo "----end---------------------------------------"
- < }
- 324a300
- >; ns_host=${ns_host:-$(hostname -s).$fwd_zone}
- 326d301
- < echo $ns_host | grep -q '\.' || ns_host=$ns_host.$fwd_zone
- 329,331c304
- < echo
- < echo "Content will be written to $db_dir/$fwd_zone :"
- < echo "----start-------------------------------------"
- ---
- >; echo "---->; Content will be written to $db_dir/$fwd_zone :"
- 349,351d321
- < [ "$to_file" ] && {
- < echo "----end---------------------------------------"
- < }
- 356,358c326
- < echo
- < echo "Content will be written to $db_dir/$rev_zone :"
- < echo "----start-------------------------------------"
- ---
- >; echo "---->; Content will be written to $db_dir/$rev_zone :"
- 373,375d340
- < [ "$to_file" ] && {
- < echo "----end---------------------------------------"
- < }
- 381c346
- < while getopts ":hgif:r:n:tub" opt; do
- ---
- >; while getopts ":$options" opt; do
- 384,388c349,350
- < g) : ;;
- < f) fwd_zone=$OPTARG ;;
- < r) rev_zone=$OPTARG ;;
- < n) ns_host=$OPTARG ;;
- < i) interact=true ;;
- ---
- >; r) : ;;
- >; s) run_spec ;;
- 390d351
- < u) update=true ;;
- 391a353
- >; f) update=true ;;
- 398,399c360,361
- < [ "$interact" = true ] && run_intact
- < [ "$update" = true ] || { check_conf $fwd_zone $rev_zone; mod_conf $fwd_zone $rev_zone; }
- ---
- >;
- >; test "$update" = true || { check_conf $fwd_zone $rev_zone; mod_conf $fwd_zone $rev_zone; }
- 401c363
- < [ "$to_file" ] || {
- ---
- >; test "$to_file" || {
复制代码 |
|