Sponsored Content
Full Discussion: Parsing nsupdate's output
Top Forums Shell Programming and Scripting Parsing nsupdate's output Post 302933174 by maverick72 on Wednesday 28th of January 2015 09:05:25 AM
Old 01-28-2015
Parsing nsupdate's output

Anybody that's ever used nsupdate knows that it's error management is not very good.

I have a wrapper script that when it's got all the information it needs launches the nsupdate command.

This is my attempt at parsing the output to help support users quickly know if the command succeded or failed (and why it failed). For some reason i cannot see, the code sometimes works and sometime doesn't ... that's with a output of 40 mixed (failed and succeded) records.

If anybody has a clue OR would has a different method of achieving the same goal i would be gratefull. Thanks.

Code:
#!/bin/awk -f

BEGIN {
        print "Start";
        RS="Outgoing update query:"
        FS="\n"
}
{
        print "#### UPDATING CNAME ####"
        # Print what we are doing in clearer form
        split ($12, update, " ")
                print update[1],update[3],update[4],update[5]
        # Print the result of the operation on the DNS server
        if ($0 ~ /opcode/)
                split($0,array," ")
                if (array[6] == "NOERROR,")
                        sub(/,$/,"",array[6]);
                        print "OPERATION:",array[6];
        # If update failed lookup error
        if ($0 ~ "update failed:")
                split($(NF-1), error, " ")
                if (error[3] == "YXRRSET")
                        print "FAIL: CNAME already exist";
        else
                print "UPDATE SUCCEDED";
        print "\n"
}
END {
        print "Done"
}

success data (2 records):
Code:
Outgoing update query:
;; ->>HEADER<<- opcode: UPDATE, status: NOERROR, id:      0
;; flags:; ZONE: 0, PREREQ: 0, UPDATE: 0, ADDITIONAL: 0
;; ZONE SECTION:
;exemple.local. IN   SOA

;; PREREQUISITE SECTION:
foo.exemple.local. 0 NONE A
foo.exemple.local. 0 NONE CNAME

;; UPDATE SECTION:
foo.exemple.local. 3600 IN CNAME realhost1.exemple.local.

Outgoing update query:
;; ->>HEADER<<- opcode: UPDATE, status: NOERROR, id:      0
;; flags:; ZONE: 0, PREREQ: 0, UPDATE: 0, ADDITIONAL: 0
;; ZONE SECTION:
;exemple.local. IN   SOA

;; PREREQUISITE SECTION:
bar.exemple.local. 0 NONE A
bar.exemple.local. 0 NONE CNAME

;; UPDATE SECTION:
bar.exemple.local. 3600 IN CNAME realhost1.exemple.local.

Failed data (also 2 records):
Code:
Outgoing update query:
;; ->>HEADER<<- opcode: UPDATE, status: NOERROR, id:      0
;; flags:; ZONE: 0, PREREQ: 0, UPDATE: 0, ADDITIONAL: 0
;; ZONE SECTION:
;exemple.local. IN   SOA

;; PREREQUISITE SECTION:
foo.exemple.local. 0 NONE A
foo.exemple.local. 0 NONE CNAME

;; UPDATE SECTION:
foo.exemple.local. 3600 IN CNAME realhost1.exemple.local.

update failed: YXRRSET
Outgoing update query:
;; ->>HEADER<<- opcode: UPDATE, status: NOERROR, id:      0
;; flags:; ZONE: 0, PREREQ: 0, UPDATE: 0, ADDITIONAL: 0
;; ZONE SECTION:
;exemple.local. IN   SOA

;; PREREQUISITE SECTION:
bar.exemple.local. 0 NONE A
bar.exemple.local. 0 NONE CNAME

;; UPDATE SECTION:
bar.exemple.local. 3600 IN CNAME realhost2.exemple.local.

update failed: YXRRSET

Expected output:
Code:
#### UPDATING CNAME ####
foo.exemple.local. IN CNAME realhost1.exemple.local.
OPERATION: NOERROR
UPDATE SUCCEDED

#### UPDATING CNAME ####
bar.exemple.local. IN CNAME realhost2.exemple.local.
OPERATION: NOERROR
FAIL: CNAME already exist

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

parsing output

I have a file that contains the output of the ls -iR command, something like this: ./results: 2504641011 result_1410 2500957642 result_525 2504641012 result_1425 2500957643 result_540 ./tests/1: 2500788755 1 2500788743 1000 ./tests/2: 2500788759 3 2500788758 999 ... (6 Replies)
Discussion started by: looza
6 Replies

2. AIX

nsupdate - 2 zones are appended to hostname?

Hello, Can someone tell me why I'm getting the following? $sudo nsupdate > update add HOSTNAME.ZONE1 86400 A IP ADDRESS > show Outgoing update query: ;; ->>HEADER<<- opcode: UPDATE, status: NOERROR, id: 0 ;; flags: ; ZONE: 0, PREREQ: 0, UPDATE: 0, ADDITIONAL: 0 ;; UPDATE SECTION:... (1 Reply)
Discussion started by: ctcuser
1 Replies

3. Shell Programming and Scripting

Parsing output

I need to parse the following out put and determine if the USB is a DISK and whether or not it's External. If an HBA line contains "USB" then does the next line contain "DISK" and "External". 0:0,31,0: HBA : (aacraid,1) AAC SCSI 0,0,0: DISK : Adaptec ASR4800SAS Volu0001 ... (6 Replies)
Discussion started by: lochraven
6 Replies

4. UNIX for Dummies Questions & Answers

nsupdate falied to update

Hello all, I am new to Unix.. i am trying to implement the TSIG in my BIND and using nsupdate to add record to bind.. this is what i did: generate the TSIG key using : dnssec-keygen HMAC-MD5 -b 128 -n HOST mydns.com forgot to mention: i am using FreeBSD. I then edit the named.conf file... (0 Replies)
Discussion started by: r_de_sousa
0 Replies

5. BSD

nsupdate failed to update

Hello all, I am new to Unix.. i am trying to implement the TSIG in my BIND and using nsupdate to add record to bind.. this is what i did: generate the TSIG key using : dnssec-keygen HMAC-MD5 -b 128 -n HOST mydns.com forgot to mention: i am using FreeBSD. I then edit the named.conf file... (0 Replies)
Discussion started by: r_de_sousa
0 Replies

6. UNIX for Advanced & Expert Users

nsupdate failed to update

Hello all, I am new to Unix.. i am trying to implement the TSIG in my BIND and using nsupdate to add record to bind.. this is what i did: generate the TSIG key using : dnssec-keygen HMAC-MD5 -b 128 -n HOST mydns.com forgot to mention: i am using FreeBSD. I then edit the named.conf file... (1 Reply)
Discussion started by: r_de_sousa
1 Replies

7. Shell Programming and Scripting

Parsing the date output

Hi fellows, I need to define a notification for SSL certificate expiration. My Command output is below: (this is the "Expiration Date") Tue Mar 15 09:30:01 2012 So, at 15th Feb (1 month before the expiration), a notification has to be triggered by a script or sth else. How can i set an... (5 Replies)
Discussion started by: oduth
5 Replies

8. Shell Programming and Scripting

parsing output

Can somebody provide a solution to parse the following; cat /tmp/xxx Name: QUE_REQU (o.mtaseast-o.dmart) (MTPost queue) Number of messages: 66446 (Age 686 min; Size 214 mb) Backlog (messages): 0 (Age 0 min) Name: QUE_REQU... (6 Replies)
Discussion started by: BeefStu
6 Replies

9. Shell Programming and Scripting

Parsing Output of a Variable

i have a log file that contains something similar to this: one two three four five six seven eight nine ten eleven twelve thirteen fourteen one two three four five six seven eight nine ten eleven twelve thirteen fourteen one two three four five six seven eight nine ten eleven twelve... (3 Replies)
Discussion started by: SkySmart
3 Replies

10. Shell Programming and Scripting

Parsing of TOP output

Hi , i am trying to set up an alert, when CPU usage (0.2%us in below output) is more than 40% top | head | grep '^Cpu' Cpu(s): 0.2%us, 0.2%sy, 0.0%ni, 99.1%id, 0.6%wa, 0.0%hi, 0.0%si, 0.0%st using CUT, i pulled the value 0.2 and assigned to CPU (variable) CPU=$(expr `top | head -10... (5 Replies)
Discussion started by: Prateek007
5 Replies
All times are GMT -4. The time now is 11:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy