LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices


Reply
  Search this Thread
Old 12-17-2007, 06:52 AM   #1
pete83
Member
 
Registered: Dec 2007
Location: The Netherlands
Distribution: Ubuntu
Posts: 50

Rep: Reputation: 15
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.
 
Old 12-17-2007, 07:14 AM   #2
JivanAmara
LQ Newbie
 
Registered: Nov 2007
Posts: 15

Rep: Reputation: 1
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.
 
Old 12-17-2007, 08:02 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You could use "getent" to retrieve values from certain administrative databases. (passwd, group, hosts, services, protocols, or networks)
 
Old 12-18-2007, 03:34 AM   #4
JivanAmara
LQ Newbie
 
Registered: Nov 2007
Posts: 15

Rep: Reputation: 1
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] nslookup, host, dig not resolving entries in /etc/hosts MensaWater Linux - Networking 27 09-22-2022 09:02 AM
Hos to boot Redhat from a USB pendrive for instalation procfs Linux - General 0 07-20-2006 10:54 PM
hosts file reverses IP and hostnames mike114327 Linux - Networking 0 10-12-2004 02:13 PM
Is There a ~/.hosts ? or anything in user level to aliasing hostnames ? cartridge Linux - Networking 2 01-12-2004 12:49 PM
hosts.compare? WeNdeL Linux - Newbie 0 01-17-2003 12:00 PM

LinuxQuestions.org > Forums > Other *NIX Forums > AIX

All times are GMT -5. The time now is 11:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration