Reputation: 21
I tried this in linux machines
my $a = $ENV{HOSTNAME};
print "\nhostname = $a\n";
i get this,
hostname = sims5.eng.netapp.com
i tried same in Solaris, but i get nothing.
hostname =
I can use below code,
use Sys::Hostname;
$host = hostname;
but is there any other way of getting hostname without importing Sys::Hostname in solaris machines.
Thanks.
Upvotes: 0
Views: 4048
Reputation: 3842
If you reeeally don't want to use modules, you can just read the hostname from the following file:
/etc/nodename
Upvotes: 3
Reputation: 50637
This is as @raina77ow suggested using source from Sys::Hostname
,
my $host = hostname() or warn "No hostname";
sub hostname {
require "sys/syscall.ph";
require "sys/systeminfo.ph";
my $host = "\0" x 65; ## preload scalar
syscall(&SYS_systeminfo, &SI_HOSTNAME, $host, 65) != -1 or return;
$host =~ tr|\0\r\n||d;
return $host;
}
Upvotes: 1