如何使用Ant来获得完全合格的主机名 [英] How to get fully qualified hostname using Ant

查看:142
本文介绍了如何使用Ant来获得完全合格的主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Ant作为我们为我们的服务器安装脚本,我们需要让我们的服务器的完全合格的名称。我怎样才能得到它使用Ant,或者在Ant是可能的吗?

完全合格的主机名是这样的:xxx.company.com


解决方案

 < EXEC可执行=主机名outputproperty =computer.hostname/>

将工作在Linux和Windows,否则使用从马克·奥康纳结果的常规解决方案
此外NSLOOKUP将工作在Linux和Windows,如果你需要fullhostname你必须为解析名称后的条目:在 Nslookup的服务器名称输出,使用:结果

 <常规>
properties.'hostname'=主机名.execute()。文本
//要么
properties.'hostname'= InetAddress.getLocalHost()。的gethostname()。properties.'hostnamefull'=NSLOOKUP $ {主机名。.execute()}文本的execute()text.find(/名称:\\ S(+)/)。分割(/:\\ S + /) [1]
< /常规><回声>
$$ {}主机名= GT; $ {}主机名
$$ {} hostnamefull = GT; $ {} hostnamefull
< /回声>

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?

The fully qualified hostname is like: xxx.company.com

解决方案

<exec executable="hostname" outputproperty="computer.hostname"/>

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屋!

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