vePortal
asked on
PERL/SED/AWK: How do I remove a zone from named.conf in a bash script.
Hello experts:
I need some major help and will assign 300 points for the best solution to my problem. Im working on a bash script that has a function that removes forward zones from bind configuration files. Ive attached a snippet of my source and need someone to fill in the blank.
I would like to be able to execute sh removezone.sh domain1.com and be able to remove
zone "domain1.com" {
type master;
file "/var/named/thevirtualserv er.com.hos ts";
};
from the named.conf
I've tried using sed to search for a domain1.com string and then remove the line that has a match but I can't remove to remove the second and fourth line.
Any kind of help would be much appreciated.
---------------------
Requirements
---------------------
2.) Have to use perl / sed /awk
3.) Have fun
I need some major help and will assign 300 points for the best solution to my problem. Im working on a bash script that has a function that removes forward zones from bind configuration files. Ive attached a snippet of my source and need someone to fill in the blank.
I would like to be able to execute sh removezone.sh domain1.com and be able to remove
zone "domain1.com" {
type master;
file "/var/named/thevirtualserv
};
from the named.conf
I've tried using sed to search for a domain1.com string and then remove the line that has a match but I can't remove to remove the second and fourth line.
Any kind of help would be much appreciated.
---------------------
Requirements
---------------------
2.) Have to use perl / sed /awk
3.) Have fun
--------------
removezone.sh
--------------
#!/bin/bash
# Declaring Variable
DOMAIN=$1
# Checking if Zone exists; if it does we will remove it.
if [[ -f /var/named/chroot/var/named/$DOMAIN.hosts ]]; then
echo "Removing $DOMAIN zone."
#Zone removal code from named.conf goes here.
rm -rf /var/named/chroot/var/named/$DOMAIN.hosts
echo "The $DOMAIN zone has been removed."
exit;
else
echo "Error: The $DOMAIN zone can not be removed as it does not exist."
exit;
fi
--------------
named.conf
--------------
zone "domain1.com" {
type master;
file "/var/named/thevirtualserver.com.hosts";
};
zone "domain2.com" {
type master;
file "/var/named/thevirtualserver.com.hosts";
};
ASKER
Hello jb1dev:
Can you think of something that would not require me to call another file. I'd like to keep it all in one if possible.
Can you think of something that would not require me to call another file. I'd like to keep it all in one if possible.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Replace $1 with $DOMAIN from your example.
Note that's the only $ in the embedded script which isn't escaped. (Appears twice)
Note that's the only $ in the embedded script which isn't escaped. (Appears twice)
usage:
./rem.pl domainname.com
Open in new window