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

89
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
eWish
971 Expert 512MB
perlfaq9

Expand|Select|Wrap|Line Numbers
  1. use Net::Domain qw(hostname hostfqdn hostdomain);
  2.  
  3. my $host = hostname();
  4. print "The host name is $host \n";
--Kevin
Aug 4 '08 #2
lilly07
89
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;
  2.  
  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.