augtool无法更新可写文件

时间:2021-05-11 13:25:29

I installed Augeas on my CentOS box and am getting unexpected behaviour from augtool.

我在我的CentOS盒子上安装了Augeas,我从augtool得到了意想不到的行为。

To whit,

要惠特,

[root@boxen tmp]# ll
-rw-r--r--. 1 root root     27 Sep 19 11:58 /tmp/my.conf

[root@boxen tmp]# cat /tmp/my.conf 
OptionOne no
OptionTwo yes

Now I want to use augtool to change OptionOne from no to yes.

现在我想使用augtool将OptionOne从no更改为yes。

[root@boxen tmp]# augtool set /tmp/my.conf/OptionOne yes
[root@boxen tmp]# augtool save

[root@boxen tmp]# cat my.conf 
OptionOne no
OptionTwo yes

augtool is not writing the config change to the file. I'm not seeing any errors. What am I doing wrong?

augtool没有将配置更改写入文件。我没有看到任何错误。我究竟做错了什么?

1 个解决方案

#1


1  

/tmp/my.conf is not a standard location for any conffile, so you need to specify which lens (i.e. parser) you want to use so Augeas knows which syntax to apply (there's tons of different conffile syntaxes, Augeas currently supports more than 150 out of the box!).

/tmp/my.conf不是任何conffile的标准位置,所以你需要指定你想要使用哪个镜头(即解析器),以便Augeas知道应用哪种语法(有很多不同的conffile语法,Augeas目前支持多于150开箱即用!)。

If you know which lens you want to use and you're using Augeas >= 1.0.0, you can use --transform for that.

如果您知道要使用哪个镜头并且使用Augeas> = 1.0.0,则可以使用--transform。

The Sshd.lns lens looks similar to your format, so you might want to use this one.

Sshd.lns镜头看起来与您的格式类似,因此您可能想要使用此镜头。

Also:

也:

  • --autosave is necessary to commit your changes, since you're not calling the save command explicitely;
  • --autosave是提交更改所必需的,因为您没有明确地调用save命令;
  • you need to use /files/tmp/my.conf/OptionOne to change the value of the node, since mapped files are exposed under /files in the Augeas tree.
  • 您需要使用/files/tmp/my.conf/OptionOne来更改节点的值,因为映射的文件在Augeas树中的/ files下公开。

So:

所以:

# augtool --autosave --transform "Sshd.lns incl /tmp/my.conf" set /files/tmp/my.conf/OptionOne yes
Saved 1 file(s)
# cat /tmp/my.conf
OptionOne yes
OptionTwo yes

#1


1  

/tmp/my.conf is not a standard location for any conffile, so you need to specify which lens (i.e. parser) you want to use so Augeas knows which syntax to apply (there's tons of different conffile syntaxes, Augeas currently supports more than 150 out of the box!).

/tmp/my.conf不是任何conffile的标准位置,所以你需要指定你想要使用哪个镜头(即解析器),以便Augeas知道应用哪种语法(有很多不同的conffile语法,Augeas目前支持多于150开箱即用!)。

If you know which lens you want to use and you're using Augeas >= 1.0.0, you can use --transform for that.

如果您知道要使用哪个镜头并且使用Augeas> = 1.0.0,则可以使用--transform。

The Sshd.lns lens looks similar to your format, so you might want to use this one.

Sshd.lns镜头看起来与您的格式类似,因此您可能想要使用此镜头。

Also:

也:

  • --autosave is necessary to commit your changes, since you're not calling the save command explicitely;
  • --autosave是提交更改所必需的,因为您没有明确地调用save命令;
  • you need to use /files/tmp/my.conf/OptionOne to change the value of the node, since mapped files are exposed under /files in the Augeas tree.
  • 您需要使用/files/tmp/my.conf/OptionOne来更改节点的值,因为映射的文件在Augeas树中的/ files下公开。

So:

所以:

# augtool --autosave --transform "Sshd.lns incl /tmp/my.conf" set /files/tmp/my.conf/OptionOne yes
Saved 1 file(s)
# cat /tmp/my.conf
OptionOne yes
OptionTwo yes