V
V
Valeriu1472017-04-06 10:42:30
bash
Valeriu147, 2017-04-06 10:42:30

How to find among the list of domain names, find the name corresponding to its IP and display this name?

Good afternoon, the second day I suffer with a simple function, but something does not work out. I have a list of servers, or rather a list of A-records. I need to resolve these A-records, find the IP corresponding to my system one and display this name in another variable.
Actually, somehow

#счетчик, начинаем с единицы, ничего не пишем
start=test
#вторая часть моего доменное имени
dns=com
#от какого по какое число у меня домены
for i in "${start}" {1..20}."$dns"; do
#вывести все это в файл
echo $i >> "/tmp/temp"
done

#смотрим этот файл
for ns in `cat /tmp/temp`; do
#тут-то и проблема, не могу понять, как лучше подобрать условие
if ; then
dig +short $ns
fi
done

But here, something is wrong with me in the second cycle, I can’t compose the condition correctly. Do not tell me where you can dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
egor_nullptr, 2017-04-06
@egor_nullptr

#!/usr/bin/env bash

start=test
dns=com

for i in {1..20}; do
    ns=$start$i.$dns
    ip=`dig +short $ns`
    if ; then
        echo "$ns -> $ip"
    fi
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question