469,270 Members | 1,117 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

perl script to find the host name

I am using following code to find the hostname/dns name of a linux server.

Expand|Select|Wrap|Line Numbers
  1. (grep {chomp;} system ('hostname -s'))[0];
And the name of the server gets printed as XXX. And I am trying assign this value to $host as below. But it is not working and $host name is null. How do I assign XXX to $host.

Expand|Select|Wrap|Line Numbers
  1. $host =(grep {chomp;} system ('hostname -s'))[0];
  2. print "The host name is $host \n";
Please let me know. Thanks.
Aug 4 '08 #1
3 27869
971 Expert 512MB

Expand|Select|Wrap|Line Numbers
  1. use Net::Domain qw(hostname hostfqdn hostdomain);
  3. my $host = hostname();
  4. print "The host name is $host \n";
Aug 4 '08 #2
Thank you so much and it worked.
Aug 4 '08 #3
Also you can try as,

Expand|Select|Wrap|Line Numbers
  1. use Sys::Hostname;
  3. my  $host = hostname;
Aug 6 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Martin Foster | last post: by
1 post views Thread by Balajisanthanakrishnan | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.