fdqn and hostname conflict

Discussion in 'Perl Misc' started by Adrian Rafferty, Aug 11, 2004.

  1. 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

    : # cat /etc/nodename
    gdwtest.au.thenational.com
    : # ./test
    Hostname = gdwtest.au.thenational.com
    : #

    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 ...

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

    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
     
    Adrian Rafferty, Aug 11, 2004
    #1
    1. Advertising

  2. Adrian Rafferty

    Ben Morrow Guest

    Quoth (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 ...
    >
    > : # hostname | perl -lne 'print
    > ((gethostbyname $_)[0])'
    > gdwtest
    > : #
    >
    > 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

    --
    "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
     
    Ben Morrow, Aug 11, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Spartaco

    hostname and dns

    Spartaco, Apr 1, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    2,440
    Spartaco
    Apr 1, 2005
  2. C
    Replies:
    1
    Views:
    852
  3. AWieminer
    Replies:
    0
    Views:
    760
    AWieminer
    Jul 12, 2005
  4. John Q
    Replies:
    1
    Views:
    1,315
    Juan T. Llibre
    Apr 14, 2008
  5. charles cashion

    css conflict (or html conflict)

    charles cashion, Feb 18, 2009, in forum: HTML
    Replies:
    2
    Views:
    806
    charles cashion
    Feb 18, 2009
Loading...

Share This Page