bash - Searching by nslookup command my own ip address from many others ip -


i have lot of virtual servers static ip-addresses, , a-records them. should use associative array installing of cms. have idea. maybe should use dig, or other dnsutil ? so, start write:

start=test dns=com in "${start}" {1..20}."$dns"; echo $i >> "/tmp/temp" done  ns in `cat /tmp/temp`; if [[ `dig +short $ns=="192.168.110.1"` ]]; dig +short $ns fi done 

but second loop wrong. can me ? should generate list domains, test1.com, test2.com ... , after should ip address. next step comparing system ip , if have ip 192.168.110.1, should domain name, test2.com. not work, broke head, have no idea, how this. please help, if possible.

the immediate error [[ `dig +short $ns=="192.168.110.1"` ]] checks whether output dig nonempty string (which isn't, because string pass in query isn't valid one). superficial fix is

if [[ `dig +short "$ns"` == "192.168.110.1" ]]; ... 

where spaces around equals operator significant, , of course, comparison should not passed dig argument; refactor script whole lot more. it's not entirely clear want script do, this?

#!/bin/bash start=test dns=com in {1..20};     host="$start.$i.$dns"     ip=$(dig +short "$host")     if [[ "$ip" == "192.168.110.1" ]];         # i'm guessing want perform reverse lookup on ip address here?         dig +short "$ip"     fi done 

Comments