如何通过perl脚本在Solaris计算机中获取主机名? [英] How to get hostname in Solaris machines, through perl script?

查看:95
本文介绍了如何通过perl脚本在Solaris计算机中获取主机名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在linux机器上尝试过

I tried this in linux machines

my $a =  $ENV{HOSTNAME};
print "\nhostname = $a\n";

我明白了

hostname = sims5.eng.netapp.com

我在Solaris中也尝试过,但是一无所获.

i tried same in Solaris, but i get nothing.

hostname = 

我可以使用以下代码

use Sys::Hostname;
$host = hostname;

但是还有其他方法可以在不将Solaris机器中导入Sys :: Hostname的情况下获取主机名.

but is there any other way of getting hostname without importing Sys::Hostname in solaris machines.

谢谢.

推荐答案

如果您以后不想使用模块,则可以从以下文件中读取主机名: /etc/nodename

If you reeeally don't want to use modules, you can just read the hostname from the following file: /etc/nodename

这篇关于如何通过perl脚本在Solaris计算机中获取主机名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆