3
value1=ns1.abc.nl.
value2=ns2.abc.nl.
value3=ns3.abc.nl.

for domains in $(cat /home/carlito/Desktop/output.txt)
           do
for nameserver in $(dig +short NS $domains)

           do
                        if [[ ( $nameserver -eq $value1 ) || ( $nameserver -eq $value2 ) || ( $nameserve$
                     then
                echo "$domains Namserver is local" >>/home/carlito/Desktop/resultaat.txt
                break


                else

                echo "$domains namserver IS NOT local" >>/home/carlito/Desktop/resultaat.txt


fi

           done
done

So i'm having trouble with the IF line of the script the error message=" nszero1.axc.nl.: syntax error: invalid arithmetic operator (error token is ".axc.nl."".

The purpose of this script= 'get output.txt (list of domains)' 'then dig +short NS $domains' and then check if its on my preferred name server $Value1,2,3 if true=good if false=bad

i already tried something like:

value="ns1.abc.nl./ns2.abc.nl/ns3.abc.nl."

for domains in $(cat /home/carlito/Desktop/output.txt)
           do
            if dig +short NS $domains == $value
                then

                echo "$domains is LOCAL"

                else

                echo"$domains Is NOT LOCAL"

          fi
done

But what this does is if domain.nl=ns1.abc.nl./ns2.abc.nl it still echo's:Is NOT LOCAL. But i want the script to Echo=true if it has at least 1 of the values.

can some one point me in the right direction which function i should use and what am i doing wrong with the if line ?

thanks in advance

Mrc
  • 43
  • 4

1 Answers1

1

You are comparing a string with a numeric value. The syntax in the below if condition is to compare two numeric value and not for string comparison. Also your if condition is not properly ended with ]]. I thing you are comparing a string with a numeric value. Please see below correct if conditions:-

First a correct if condition if both the right and left hand values are numeric :-

if [[ ( $nameserver -eq $value1 ) || ( $nameserver -eq $value2 ) ]]

For correct string comparison:-

if [[ ( "$nameserver" == "$value1" ) || ( "$nameserver" == "$value2" ) ]]

Hope this will help you.

Abhijit Pritam Dutta
  • 5,521
  • 2
  • 11
  • 17