我使用Ant作为服务器的安装脚本,我们需要获取服务器的完全限定名称.如何使用Ant获取它,或者在Ant中是否可以?
完全限定的主机名如下:xxx.company.com
<exec executable="hostname" outputproperty="computer.hostname"/>
Run Code Online (Sandbox Code Playgroud)
将在Linux和Windows上工作,否则使用来自Marc O'Connor的groovy解决方案
另外nslookup将在linux和windows上工作,如果你需要fullhostname你必须在Name之后解析条目:在nslookup ServerName输出中,使用:
<groovy>
properties.'hostname' = "hostname".execute().text
//or
properties.'hostname' = InetAddress.getLocalHost().getHostName()
properties.'hostnamefull' = "nslookup ${"hostname".execute().text}".execute().text.find(/Name:\s(.+)/).split(/:\s+/)[1]
</groovy>
<echo>
$${hostname} => ${hostname}
$${hostnamefull} => ${hostnamefull}
</echo>
Run Code Online (Sandbox Code Playgroud)