LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-13-2005, 03:19 AM   #1
farry
LQ Newbie
 
Registered: Mar 2005
Location: UK
Posts: 4

Rep: Reputation: 0
gethostbyname in script?


How do I assign the IP address of a given hostname to an environment variable in a bash script? I want to use the same lookup methods as the gethostbyname system call. i.e. it needs to use both the /etc/hosts file and dns lookup to try to find the IP.
 
Old 03-13-2005, 09:29 PM   #2
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
there is a little thingy in bind utils that will do that i think called "host"
if it outputs too much cruft you can change it a little or parse its output a little either way
or just write a little backend c thing yourself
 
Old 03-14-2005, 02:14 AM   #3
farry
LQ Newbie
 
Registered: Mar 2005
Location: UK
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks, but that seems to do a dns lookup, but doesn't refer to the /etc/hosts file. i.e. I can ping a machine in the hosts file by name, but the host utility can't find it.
 
  


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
Using the gethostbyname command mdlister Linux - Newbie 5 03-14-2005 07:50 AM
gethostbyname() error jnusa Programming 0 01-12-2005 04:56 AM
Problem with # and gethostbyname lolilol Linux - Software 0 04-26-2004 05:29 AM
Problem w/ gethostbyname() robeb Linux - Networking 3 05-22-2002 08:42 AM
gethostbyname error for aimstr8 Linux - Security 7 03-09-2002 04:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:15 PM.

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