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.
#!/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):
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):
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:
#### 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