如何读取 jboss-cli 中的第一个主机名

huangapple go评论68阅读模式
英文:

How can I read first host name in jboss-cli

问题

I'm writing a jboss-cli script which manipulates the servers in a host.xml file, however I'm not able to retrieve the host name (the name has to be dynamic).

I am able to get a list of the current host names with the following

set host=`:read-children-names(child-type=host)`

but the value returned is a list, not a single item.

echo $host
["master"]

Is there a way to get the first host in the list? Or is there an alternative way to read the current host? (we're never expecting more than one)

Thanks if you can help!

EDIT: My workaround was to use the COMPUTERNAME environment variable (Wildfly is running on Windows), knowing that the Wildfly host name should always be the same as the computer name. (This customer's servers are all set up in this way). However, I would prefer to do this properly.

英文:

I'm writing a jboss-cli script which manipulates the servers in a host.xml file, however I'm not able to retrieve the host name (the name has to be dynamic).

I am able to get a list of the current host names with the following

set host=`:read-children-names(child-type=host)`

but the value returned is a list, not a single item.

echo $host
["master"]

Is there a way to get the first host in the list? Or is there an alternative way to read the current host? (we're never expecting more than one)

Thanks if you can help!

EDIT: My workaround was to use the COMPUTERNAME environment variable (Wildfly is running on Windows), knowing that the Wildfly host name should always be the same as the computer name. (This customer's servers are all set up in this way). However, I would prefer to do this properly.

答案1

得分: 1

翻译好的内容如下:

给定您想获取正在使用的主机名,您可以使用 local-host-name 属性。

set host=`:read-attribute(name=local-host-name)`

这将产生类似以下的输出:

[domain@embedded /] echo $host
primary
英文:

Given you want to get the host name in use, you can use the local-host-name attribute.

set host=`:read-attribute(name=local-host-name)`

That produces something like:

[domain@embedded /] echo $host
primary

huangapple
  • 本文由 发表于 2023年3月31日 21:58:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75899382.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定