I have a basic script I wrote to go through a list of ip addresses and return the hostname for it. I pretty much use a while loop like here:
Code:
while read ip
do
host $ip
done < ip.txt
That's fine but some of them don't return a hostname at that particular time (some systems go down). Instead what I'd like to do is have my own mapping of ip's to hostnames so that when new data comes in and I run a list of ip's to it, it will return the value of what is in my other file first (like a small database), then if it doesn't find it, run the host $ip on it to return that value. I just want a basic two field file created.
ip.addr.of.machine hostname
ip.addr.of.machine hostname
...
What would be the most efficient way to start executing this script? If it sounds confusing, I get a list of IPs, I place it in a plain text file and I run the script I have above feeding the file into it. It returns the hostname which is ok but some of them are down OR simply do not respond (I have a list of their hostnames in another file). How could I basically make a new list of the two field file that I want with the original ip in the first field and the hostname right next to it? I'd like to build this two field file so that it becomes my database for when I feed new ip's to my script, it grabs the hostname from it and appends it to another file. Thanks.