compare the hostnames in /etc/hosts with the result of nslookup on a ip from /etc/hos
I want to compare the hostnames in /etc/hosts with the result of nslookup on a ip from /etc/hosts.
So i want to put each ip from /etc/hosts in a variable and then do a nslookup on that ip. And after that compare the hostname wich comes up after running nslookup to the hostname in the /etc/hosts file. Shell scripting is still quite new for me so i don't know really where to begin. I did something like this: cat /etc/hosts | grep -v # | while read LINE do echo $LINE done but i don't know how print out line by line. Is there a other way to do this? Please give me a push in the right direction. |
Reading lines instead of tokens trips me up too...
but the following code will process each line one by one:
for n in {1..file_length}; do head -$n /etc/hosts | tail -1 | your_command ; done where "file_length" is the number of lines in your /etc/hosts file. and "your_command" is what you want to do to the line. leave out the pipe to "your_command" and it essentially echos the file one line at a time. If there's a better way to do this without resorting to a real computer language, I'd like to know too. Hope that helps. |
You could use "getent" to retrieve values from certain administrative databases. (passwd, group, hosts, services, protocols, or networks)
|
Thanks jschiwal
Never met the "getent" critter before. While it's useful for this user's specific problem, what's a good way in general to pull a single line from a file. Piping through head and tail seems a bit of a kludge to me.
Cheers |
All times are GMT -5. The time now is 02:29 AM. |