How to export named to CSV?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to export named to CSV?
# 1  
Old 02-12-2014
How to export named to CSV?

I am really shooting for the moon here but I really want to be able to break down our named.conf file into a CSV file so I can easily see what options are for each zone.

Here are two basic entries as examples:
Code:
zone "mywiseguys.com" {
        type slave;
        file "xweb.dir/db.mywiseguys.com";
        masters {10.103.13.60; };
};

zone "hosangit.com" {
        type master;
        file "xweb.dir/db.hosangit.com";
};

I would like to be able to parse the results so
column A = zone
column B = type
column C = file
column D = masters

Is this possible using ksh?
# 2  
Old 02-12-2014
Using awk:
Code:
awk '
        BEGIN {
                print "Zone,Type,File,Masters"
        }
        /zone/ {
                c += 1
                gsub ( /\"/, x, $2 )
                Z[c] = $2
        }
        /type/ {
                sub ( /\;/, x, $2 )
                T[c] = $2
        }
        /file/ {
                gsub ( /\"|\;/, x, $2 )
                F[c] = $2
        }
        /masters/ {
                n = match ( $0, /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/, I )
                M[c] = I[0]
        }
        END {
                for ( i = 1; i <= c; i++ )
                        print Z[i], T[i], F[i], M[i] ? M[i] : "NA"
        }
' OFS=, named.conf

# 3  
Old 02-12-2014
Thanks, I see where you are going with the awk command. I tried running it but get
Code:
awk: syntax error near line 7
awk: illegal statement near line 7
awk: newline in string near line 7
awk: syntax error near line 11
awk: illegal statement near line 11
awk: illegal statement near line 11
awk: syntax error near line 15
awk: illegal statement near line 15
awk: newline in string near line 15
awk: syntax error near line 19
awk: illegal statement near line 19
awk: syntax error near line 24
awk: illegal statement near line 24

# 4  
Old 02-12-2014
Use nawk or /usr/xpg4/bin/awk instead on SunOS or Solaris.
# 5  
Old 02-12-2014
Working much better.

Now my error is:
Code:
nawk: syntax error at source line 19
 context is
                        n = match ( $0, >>>  /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/, <<<  I )
nawk: illegal statement at source line 19

# 6  
Old 02-12-2014
I don't have access to a Solaris env to test this. Try with this change:
Code:
        /masters/ {
                n = match ( $0, /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ )
                if ( n )
                        M[c] = sprintf ( "%s", substr ( $0, RSTART, RLENGTH ) )
        }

# 7  
Old 02-12-2014
Worked GREAT! Thank You very much.. that is so awesome

---------- Post updated at 03:27 PM ---------- Previous update was at 02:53 PM ----------

Ran into a weird issue with the script that maybe you'll understand.

named.conf
Code:
zone "uk-mywiseguys.com" {
        type master;
        file "corp.dir/db.uk-mywiseguys.com";
};

zone "mywiseguys.com" {
        type master;
        file "corp.dir/mwg.zone";
        also-notify { 12.5.6.1; 20.16.19.13; };
};

zone "ukweb.mywiseguys.com" {
        type master;
        file "mwgcorp.dir/db.ukweb.mywiseguys.com";
};

Result was
Code:
uk-mywiseguys.com,master,corp.dir/db.uk-mywiseguys.com,NA
mywiseguys.com,master,,NA
corp.dir/mwg.zone;,,corp.dir/mwg.zone,NA
ukweb.mywiseguys.com,master,corp.dir/db.ukweb.mywiseguys.com,NA

Notice how it totally tripped on the second entry. Weird.


Another weird thing...
named.conf
Code:
zone "ourholychurch.com" {
        type master;
        file "primary.dir/db.ourholychurch.com";
};

// =====================================
// keyword: start mwgcorp
// Zone files for /var/named/mwgcorp.dir
// Domains owned by MyWiseGuys Corporation
// =====================================

zone "aa-mwg.com" {
        type slave;
        file "corp.dir/db.aa-mwg.com";
        masters {20.10.3.6; };
};

Results
Code:
ourholychurch.com,master,Zone,NA
aa-mwg.com,slave,corp.dir/db.aa-mwg.com,20.10.3.6

The first one didn't work so good.... weird.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Export Oracle multiple tables to multiple csv files using UNIX shell scripting

Hello All, just wanted to export multiple tables from oracle sql using unix shell script to csv file and the below code is exporting only the first table. Can you please suggest why? or any better idea? export FILE="/abc/autom/file/geo_JOB.csv" Export= `sqlplus -s dev01/password@dEV3... (16 Replies)
Discussion started by: Hope
16 Replies

2. Shell Programming and Scripting

Script to Gather data from logs and export to a CSV file

Greetings, After a few hours of trial and error, I decide to ask for some help. I am new to AWK and shell script, so please don't laugh :p I made the below script, to gather data from some logs and have the output into a CSV file : #!/bin/sh #Script to collect Errors ... (9 Replies)
Discussion started by: Yagami_Sama
9 Replies

3. Linux

Parsing - export html table data as .csv file?

Hi all, Is there any out there have a brilliant idea on how to export html table data as .csv or write to txt file with separated comma and also get the filename of link from every table and put one line per rows each table. Please see the attached html and PNG of what it looks like. ... (7 Replies)
Discussion started by: lxdorney
7 Replies

4. Shell Programming and Scripting

Parsing cisco cfg to export as csv

I have been looking everywhere for a solution and it seems as though awk may do the trick. I am very much a newbie in the awk scripting world but it seems to appear one of the best text parsing tools from what I've read on this forum. Scenario: I have about 50 cisco config files randomly... (7 Replies)
Discussion started by: djzah
7 Replies

5. Shell Programming and Scripting

Match columns from two csv files and update field in one of the csv file

Hi, I have a file of csv data, which looks like this: file1: 1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628 2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Discussion started by: djoseph
10 Replies

6. Shell Programming and Scripting

Comparing 2 CSV files and sending the difference to a new csv file

(say) I have 2 csv files - file1.csv & file2.csv as mentioned below: file1.csv ID,version,cost 1000,1,30 2000,2,40 3000,3,50 4000,4,60 file2.csv ID,version,cost 1000,1,30 2000,2,45 3000,4,55 6000,5,70 ... (1 Reply)
Discussion started by: Naresh101
1 Replies

7. Shell Programming and Scripting

Perl search csv fileA where two strings exist on another csv fileB

Hi I have two csv files, with the following formats: FileA.log: Application, This occured blah Application, That occured blah Application, Also this AnotherLog, Bob did this AnotherLog, Dave did that FileB.log: Uk, London, Application, datetime, LaterDateTime, Today it had'nt... (8 Replies)
Discussion started by: PerlNewbRP
8 Replies

8. Shell Programming and Scripting

CSV to SQL insert: Awk for strings with multiple lines in csv

Hi Fellows, I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem: I have csv files in the following pipe-delimited format: Column1|Column2|Column3|Column4|NEWLINE Address Type|some descriptive... (4 Replies)
Discussion started by: khayal
4 Replies

9. Shell Programming and Scripting

Need to compare two csv files values and write into another csv file

Hi all, Am new to scripting. So i just need your ideas to help me out. Here goes my requirement. I have two csv files 1.csv 2.csv abc,1.24 abc,1 def,2.13 def,1 I need to compare the first column of 1.csv with 2.csv and if matches then need to compare... (2 Replies)
Discussion started by: chinnahyd
2 Replies

10. Shell Programming and Scripting

unix script to export data from csv file to oracle database

Hello people, Need favour. The problem I have is that, I need to develop a unix shell script that performs recurring exports of data from a csv file to an oracle database. Basically, the csv file contains just the first name and last name will be dumped to an Unix server. The data from these... (3 Replies)
Discussion started by: vinayagan
3 Replies
Login or Register to Ask a Question