nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

BIND named.conf search zone and comment it out script

This is a discussion on BIND named.conf search zone and comment it out script within the Shell scripting forums, part of the Development/Scripting category; Hi I've a file called /etc/named.conf I want a script which could search for a given domain name and then ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 14-06-2009, 02:17 AM
Senior Member
User
 
Join Date: Jul 2006
Posts: 145
Thanks: 0
Thanked 2 Times in 2 Posts
Rep Power: 4
asim.mcp is on a distinguished road
Default BIND named.conf search zone and comment it out script

Hi


I've a file called /etc/named.conf

I want a script which could search for a given domain name and then comment it as well. Can anyone let me know how would be it possible to COMMENT/UN COMMENT the fields related to that domain name?
Reply With Quote
  #2 (permalink)  
Old 14-06-2009, 08:18 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Is named.conf domain done via include statement or direct zone file? For e.g. following will print zone name:
PHP Code:
egrep  '^zone.+example\.com.+$' named.conf 
O/P
Code:
zone "example.com" {
PHP Code:
egrep -A 4  '^zone.+example\.com.+$' named.conf.local 
O/P
Code:
zone "example.com" {
        type master;
        file "/etc/bind/zones/e/example.com";
        allow-transfer { singlemaster; };
};
Now to comment out entire zone simple run it as (note -v will remove all matched line):
PHP Code:
egrep --A 4  '^zone.+example\.com.+$' named.conf.local 
Here is sample bash code:

PHP Code:
#!/bin/bash
# run it as ./script.sh example.com
OUT=/tmp/named.$$.conf
NAMED
=/etc/named.conf
BAK
=/root/named/named.conf.$(date +"%m-%d-%T_%P")

### no editing ###
DOM=$1
die(){
    echo 
"$@"
    
exit 99
}
"$DOM" == "" ] && die  "Specify domain name"
F1=$(echo $DOM cut -d'.' -f1)
F2=$(echo $DOM cut -d'.' -f2)


egrep "^zone.+${F1}\.${F2}.+$\" $NAMED >/dev/null
[ $? -ne 0 ] ^^ die "
$DOM does not exists in $NAMED"

[ ! -d $(dirname $BAK) ] &&  echo "
mkdir -$(dirname $BAK)"
/bin/cp $NAMED $BAK
egrep -v -A 4  "
^zone.+${F1}.${F2}.+$" $NAMED > $OUT
/bin/cp -f $OUT $NAMED 
Again test it offline and adjust as per your named.conf format. This will do find and replace for search and comment out use sed, which is going to bit complicated.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 15-06-2009, 12:39 PM
Senior Member
User
 
Join Date: Jul 2006
Posts: 145
Thanks: 0
Thanked 2 Times in 2 Posts
Rep Power: 4
asim.mcp is on a distinguished road
Default

Thanks for your help.

When i run this script, its generating the following error.


./testing: line 23: unexpected EOF while looking for matching `"'
./testing: line 25: syntax error: unexpected end of file
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Shell Script For Dns BIND Server Configuration ramjgn Shell scripting 4 24-03-2009 06:32 PM
Shell BIND NAMED Zone Creation Script asim.mcp Shell scripting 4 13-02-2009 04:51 PM
getting errors from named.conf in rhel5 ashu.wifi CentOS / RHEL / Fedora 2 17-09-2008 02:02 PM
script to search a "sentence" on a group of files. permalac Shell scripting 2 04-09-2008 12:24 PM
Linux Change the time zone configuration after installation raj Linux software 1 17-07-2006 02:11 AM


All times are GMT +5.5. The time now is 02:57 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38