如何使用 Ant 获取完全限定的主机名 [英] How to get fully qualified hostname using Ant
问题描述
我使用 Ant 作为我们服务器的设置脚本,我们需要获取我们服务器的完全限定名称.我如何使用 Ant 获得它,或者在 Ant 中可以实现?
I am using Ant as our setup script for our server, and we need to get the fully qualified name of our server. How can I get it using Ant, or is is possible in Ant?
完全限定的主机名类似于:xxx.company.com
The fully qualified hostname is like: xxx.company.com
推荐答案
<exec executable="hostname" outputproperty="computer.hostname"/>
将在 linux 和 windows 上运行,否则使用 Marc O'Connor 的 groovy 解决方案
nslookup 也适用于 linux 和 windows,如果您需要完整的主机名,您必须解析 Name: 在 nslookup ServerName
输出后的条目,使用 :
will work on linux and windows, otherwise use the groovy solution from Marc O'Connor
Also nslookup will work on linux and windows, if you need the fullhostname you have to parse for the entry after Name: in nslookup ServerName
output, use :
<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>
这篇关于如何使用 Ant 获取完全限定的主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!