Search and Destroy Script Direction Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search and Destroy Script Direction Help
# 1  
Old 03-04-2014
Search and Destroy Script Direction Help

Being a beginner in scripting I am not sure the direction to take to accomplish the below task and would love suggestions.

GOAL
input file: domains.list
Read input file, search in named.conf and find domain and delete entry for the purpose of cleanup activity.

named.conf entry example
Code:
zone "hosangit.biz" {
                type slave;
                file "primary.dir/db.hosangit.biz";
                masters { 192.8.15.7; };
};

So the file somehow needs to read line by line the domains then look in the named.conf for exactly "hosangit.biz" (not na.hosangit.biz) and then remove everything from the word zone to the last }; prompt

Take into account the entry may be commented out like the following
Code:
//zone "hosangit.com" {
//        type slave;
//        file "primary.dir/db.hosangit.com"
//    masters { 192.8.15.8; };
//};

Would love to have a list of what was removed as well so I can validate everything is okay.

Suggestions on which route to take? Is this doable in korn scripting or awk scripting. I think someone said sed would be helpful with the searching portion. Again, I'm new and want to learn. Instead of altering 2000+ domains on 5 different servers manually (which I have been doing) it seems there should be a way to do this via a script.

Any help is appreciated.
# 2  
Old 03-04-2014
Do you want the commented out zones to be removed as well?
# 3  
Old 03-04-2014
Quote:
Originally Posted by RudiC
Do you want the commented out zones to be removed as well?
Yes, that would be part of it as well. A complete clean up activity of the named.conf of anything that is in the domains.txt input file
# 4  
Old 03-04-2014
Try this as a starter. domains.txt is not yet read, but ...
Code:
awk     '/{/            {CNT++}
         /}/            {CNT--}
         $0 ~ SRCH      {FN=SRCH".txt"}
         CNT && FN      {print $0 > FN; next}
         !CNT           {FN=""}
         1
        ' SRCH="\"hosangit.biz\"" file

# 5  
Old 03-04-2014
Thanks, it worked pretty good.

It didn't remove the last };

Before snapshot
Code:
zone "djzah.com" {
      type master;
      file "trade.dir/db.djzah.com";
};

zone "hosangit.biz" {
        type slave;
        file "primary.dir/db.hosangit.biz";
        masters {20.10.3.5; };
};

AFTER script
Code:
zone "djzah.com" {
      type master;
      file "trade.dir/db.djzah.com";
};

};


So that trailing };

I also tested the commented out zone's
Before
Code:
zone "djzah.com" {
      type master;
      file "trade.dir/db.djzah.com";
};

//zone "hosangit.biz" {
//        type slave;
//        file "primary.dir/db.hosangit.biz";
//        masters {20.10.3.5; };
//};

After
Code:
zone "djzah.com" {
      type master;
      file "trade.dir/db.djzah.com";
};

//};

So you can see the extra or left behind is the //};
# 6  
Old 03-04-2014
OK, try this one:
Code:
awk     'FNR==NR        {T[$1]++; next}
         /{|}/          {CNT += gsub (/{/,"&") - gsub (/}/,"&")}
         /zone/         {for (i in T) if ($0 ~ i) {FN=i".txt"}; gsub (/"/,"",FN)}
         FN             {print > FN; if (!CNT) {FN=""}; next}
         1
        ' domain.txt file

This User Gave Thanks to RudiC For This Post:
# 7  
Old 03-05-2014
That code works great RudiC exporting the actual entire zone into its own text file. (Creating Backups of the domains). I'll admit the code is way advanced. I'm going to try and break down each of your steps so I can learn how you did it and see if I can apply it to the remove portion. Thank You for giving me that push.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to destroy corrupt zpool without importing it?

A couple of spare disks have been added to a Solaris 10 system, and one of them has a corrupt zpool on it. I don't care about the data: I want to destroy it and re-use the disk, but it's corrupt so I can't import it. The corrupt pool is called "rpool" so I don't want to destroy it by name... (2 Replies)
Discussion started by: Mysturji
2 Replies

2. What is on Your Mind?

How to destroy one's business...?

I don't know enough about this subject but this is for the big guns... Yesterday:- Man accidentally 'deletes his entire company' with one line of bad code | News | Lifestyle | The Independent (5 Replies)
Discussion started by: wisecracker
5 Replies

3. Shell Programming and Scripting

Script going upward and downward direction

Hello, I have a log file as shown below. Each line starts with instance nr. : Session: IP Processing HTTP Socket Command : Connecting User-Agent Media: : NOT Rejected Media : Session: Username Request Channel : Username : Check if he is in User Database : Username : not in the... (6 Replies)
Discussion started by: baris35
6 Replies

4. Hardware

Plop boot manager Destroy the pc

Hello friends , yesterday i used plop boot manager to shutdown the pc but after using it, nothing happened on screen , i mean cpu is running but monitor show blank screen and then i reassembled the whole pc again ,cleaned , reattach all the devices again but problem persist . Any help (0 Replies)
Discussion started by: rink
0 Replies

5. Solaris

ZFS - Dataset / pool name are the same...cannot destroy

I messed up my pool by doing zfs send...recive So I got the following : zpool list NAME SIZE ALLOC FREE CAP DEDUP HEALTH ALTROOT rpool 928G 17.3G 911G 1% 1.00x ONLINE - tank1 928G 35.8G 892G 3% 1.00x ONLINE - So I have "tank1" pool. zfs get all... (8 Replies)
Discussion started by: eladgrs
8 Replies

6. Shell Programming and Scripting

How to recursively search and destroy tabs

Inspite of my best efforts, eclipse 3.5 seems to continue to misbehave and insert tab characters in my source code. How do I write a script execute from emacs to search all my files for tab characters and conveniently position me on the line of code that has the offending tab? Here are my... (7 Replies)
Discussion started by: siegfried
7 Replies

7. Shell Programming and Scripting

sed -i destroy symlink - how to solve this ?

After a few hours of frustration because I didn't understand why my symlinks are destroyed i just found out that sed -i will destroy symlinks. I searched but i didn't found any good solution for this. Is there any way to overcome this ? On my ubuntu server sed version is 4.1.5 edit: Sorry... (0 Replies)
Discussion started by: ktm
0 Replies

8. Solaris

How to destroy hardware raid on T5120

Hi, I have problem creating hardware raid on T5120 with 4 disks. After the hardware raid 1 created, then I used the raidctl -l c1t0d0 and raidctl -l c1t2d0 the output of volume c1t0d0 contain disk 0.0.0 0.1.0, also the volume c1t2d0 contain disk 0.0.0 0.1.0 and should be 0.2.0 0.3.0 so I... (15 Replies)
Discussion started by: netlink
15 Replies

9. Debian

Don't want destroy windows! Ask skills

I am going to install Linux/Debian on my computer. My current OS is windows 98. My question is that if I install Linux, it is required to partition the hard drive. Windows may be destroyed. I still want to keep it. I have no windows installtion CD. I don't want to buy it. Can I avoid... (1 Reply)
Discussion started by: zhshqzyc
1 Replies

10. UNIX for Dummies Questions & Answers

Looking for a good way to search & destroy lines

What is a good way to find an entry in a .conf file and then remove all lines associated with that entry? I have a Samba server running on Linux that I would like to easily add/remove share entries in the smb.conf file without removing or deleting lines that are not associated with that section.... (5 Replies)
Discussion started by: darthur
5 Replies
Login or Register to Ask a Question