fdqn and hostname conflict

A

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";
#


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

(e-mail address removed): # cat /etc/nodename
gdwtest.au.thenational.com
(e-mail address removed): # ./test
Hostname = gdwtest.au.thenational.com
(e-mail address 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 address removed): # hostname | perl -lne 'print
((gethostbyname $_)[0])'
gdwtest
(e-mail address 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
 
B

Ben Morrow

Quoth (e-mail address 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 address removed): # hostname | perl -lne 'print
((gethostbyname $_)[0])'
gdwtest
(e-mail address 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::Domain, which will return the fqdn,
hostname and domainname separately.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top