Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > fdqn and hostname conflict

Reply
Thread Tools

fdqn and hostname conflict

 
 
Adrian Rafferty
Guest
Posts: n/a
 
      08-11-2004
Hi,

i'm trying a dummy perl script on solaris ....

# cat test

#!/bin/perl -w
use Sys::Hostname;
my $hostname = hostname();

print "Hostname = $hostname\n";
#


the problem that i have is that some of the hosts have an
/etc/nodename
= to the fqdn , others have the none fqdn nodename

http://www.velocityreviews.com/forums/(E-Mail Removed): # cat /etc/nodename
gdwtest.au.thenational.com
(E-Mail Removed): # ./test
Hostname = gdwtest.au.thenational.com
(E-Mail Removed): #

i.e ..
n144110@webjump2: $ ./test
Hostname = webjump2
n144110@webjump2: $

How can i change the output of the script to be "gdwtest"
i.e. the first field of the fqdn ??

I have tried ...

(E-Mail Removed): # hostname | perl -lne 'print
((gethostbyname $_)[0])'
gdwtest
(E-Mail Removed): #

which returns the correct o/p , but i'm not sure how to integrate it
with the
original perl script.

the correct o/p is also displayed in the host without the fqdn ...
n144110@webjump2: $ hostname | perl -lne 'print ((gethostbyname
$_)[0])'
webjump2
n144110@webjump2: $


which returns the correct o/p , but i'm not sure how to integrate it
with the
original perl script.




Any help greatly appreciated,
Regards Adrian
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      08-11-2004

Quoth (E-Mail Removed) (Adrian Rafferty):
> Hi,
>
> i'm trying a dummy perl script on solaris ....
>
> # cat test
>
> #!/bin/perl -w
> use Sys::Hostname;
> my $hostname = hostname();
>
> print "Hostname = $hostname\n";
> #
>
> How can i change the output of the script to be "gdwtest"
> i.e. the first field of the fqdn ??
>
> I have tried ...
>
> (E-Mail Removed): # hostname | perl -lne 'print
> ((gethostbyname $_)[0])'
> gdwtest
> (E-Mail Removed): #
>
> which returns the correct o/p , but i'm not sure how to integrate it
> with the
> original perl script.


Try

print "Hostname = ", (gethostbyname hostname)[0];

if the other reply (simply extracting the first bit) isn't good enough.

You may also be better off with Net:omain, which will return the fqdn,
hostname and domainname separately.

Ben

--
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
-Assyrian stone tablet, c.2800 BC (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
css conflict (or html conflict) charles cashion HTML 2 02-18-2009 09:41 PM
ASP.NET and Current hostname and Port John Q ASP .Net 1 04-14-2008 06:22 PM
RMI: take ip/hostname what client was using and give it back as aremote objects hostname AWieminer Java 0 07-12-2005 08:05 PM
hostname and dns Spartaco ASP .Net 5 04-01-2005 03:29 PM
Solaris 9 and InetAddress with IP hostname C Java 1 09-16-2003 12:27 PM



Advertisments