1

My /etc/hosts look like this:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.13.11   idm.myhost.com
192.168.13.10   dnsf.myhost.com
192.168.13.11   idm.myhost.com
192.168.13.10   dnsf.myhost.com
192.168.13.11   idm.myhost.com
192.168.13.10   dnsf.myhost.com
192.168.13.10   temp1.myhost.com

I can query duplicated lines by query below:

 print /files/etc/hosts/*/canonical["idm.myhost.com"]

or either use regex

defvar mypath /files/etc/hosts
print $mypath/*/*[.=~ regexp("dnsf.myhost.com")]

But I can't remove these matched lines with a simple rm

rm /files/etc/hosts/*/canonical["idm.myhost.com"]

The problem is, augtool just removes the canonical leaf from the node and ipaddr remains. it cause the save function to returns error. I don't want to use bash script and I try to solve the problem with augeas itself. Assist, please...

P.S. I couldn't find a complete tutorial or document for this useful tool. I would be thankful is someone can propose a good document. I've searched all the web and just found a few simple examples.

4

1 回答 1

2

您的表达式选择规范节点而不是主机节点。如果要删除主机节点,需要使用:

rm /files/etc/hosts/*[canonical="idm.myhost.com"]

这将选择 下的任何条目/files/etc/hosts canonical子节点具有 value idm.myhost.com

至于文档,在 Augeas 网站上有一个教程,在 Augeas wiki上还有一些文档。

Youtube 上还有一段关于 Augeas 的视频介绍。

我大约 7 年前开始写一本书,现在仍然可以在网上找到,但从来没有花时间完成它。

于 2020-09-04T20:39:37.447 回答