Bash: pinging servers and writing the IP to a file

92 views Asked by At

I currently have to find the IP-Adresses of a lot of servers.

I have written a bash script on linux that creates all the server names.

When I write it like this, I get all servernames, even if there no longer have an IP.

host $f$n$d >> IPs.txt

Is there a way to only write the servers into the file, that still have an IP, together with the servername.

Kind regards Elias

1

There are 1 answers

2
Antonio Petricca On

I think the local DNS resolver caches the IP addresses, so you will get the corresponding IPs even in the scenario you described.

I suggest you to start the script with a full local DNS flush, depending on your distribution and DNS client: Here are son techinques to flush it.