Shell script help.

Hello.

The idea is to query a DNS to check de NS record, if the domain name exist in table, print "Is authoritative" else " Not authoritative"

I don�t know if to use "awk" and "grep" creating a /tmp/file then read ir from there or what...

#!/bin/bash
clear
echo -n "First DNS to query: "
read dns
echo -n "Domain name to check: "
read domain
echo "`dig @$dns $dominio ns`"
if [ #here is my problem# ]
then
echo "DNS for $domain is authoritative"
fi
else
echo " DNS is NOT authoritative for $domain"

Sorry guys, need HELP.

Your other duplicate post was deleted - please read the rules

what would be the output of dig @$dns $dominio ns ??
you want to check based on this output right ??

The output would be something like this.

It is an ordinary DIG query.

dig @(server) (domain name) (query type)

E.G.

; <<>> DiG 8.3 <<>> @ns1.sitelutions.com unix.com
; (1 server found)
;; res options: init recurs defnam dnsrch
;; got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 65394
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 5, ADDITIONAL: 5
;; QUERY SECTION:
;; unix.com, type = A, class = IN

;; ANSWER SECTION:
unix.com. 1H IN A 144.202.242.190

;; AUTHORITY SECTION:
unix.com. 30M IN NS ns1.sitelutions.com.
unix.com. 30M IN NS ns2.sitelutions.com.
unix.com. 30M IN NS ns3.sitelutions.com.
unix.com. 30M IN NS ns4.sitelutions.com.
unix.com. 12H IN NS ns5.sitelutions.com.

;; ADDITIONAL SECTION:
ns1.sitelutions.com. 2D IN A 66.117.40.216
ns2.sitelutions.com. 1M IN A 69.26.176.28
ns3.sitelutions.com. 2D IN A 63.219.151.5
ns4.sitelutions.com. 2D IN A 82.96.97.28
ns5.sitelutions.com. 2D IN A 69.93.94.154

This is what matter for me: flags: qr aa rd >> aa

The first issue is that he hasn't checked his spelling:

Change dominio to domain to get this to start working a little better.

Second, check syntax of the IF statement. elif, else, and fi. See the man page for bash inbedded if statement.

Third, either use a temporary file to put the output into so you can use your choice of grep/awk to find what you are looking for - if it's found (grep -c will give you the number of times a string was found) then output something, else output something.

Excellent.

ok, the dominio to domain will be changed.

I will read the "man" for grep (-c), could you give me a little push on how do I need to write the statement IF with GREP ?

If you can�t, no problem, it was a great help.

Thanks a lot. !!!

There are many topics discussed using grep for this kind of stuff, here is one link processing line in file

look for the user "new2prog" post....

Please also search the forum before posting your question....

OK, thanks a lot.

I will check forum first, but the problem was that I dind�t knwe about using grep -c in a IF statement (how can I search something that I don�t know).

I will first read posts and then write mine if I dont find my solution.

Thanks again. :�

ok no problem...

here it is

#!/bin/ksh

clear
echo -n "First DNS to query: "
read dns
echo -n "Domain name to check: "
read domain
$gval=$(dig @$dns $domain ns | grep -c "qr aa rd" )
if (( $gval > 0 ))
then
echo "DNS for $domain is authoritative"
else
echo " DNS is NOT authoritative for $domain"
fi

U R AWSOME mahendramahendr

:smiley:

Thanks.