【问题标题】:Why does the file name needs to be repeated?为什么需要重复文件名?
【发布时间】:2014-06-01 13:21:56
【问题描述】:

如果我这样做

augtool --noautoload --transform "sshd incl /etc/ssh/sshd_config" ls "/files/etc/ssh/sshd_config/"

然后我得到/etc/ssh/sshd_config的树形结构,但是这里我写了两次文件路径,最后一次以/files为前缀。

问题

是否可以这样做,但只指定文件路径?

【问题讨论】:

  • 您根本没有重复相同的路径。第一个路径是 /etc/ssh/sshd_config ,它似乎是一个文件,另一个是 /files/etc/ssh/sshd_config/ ,它似乎是一个目录(基于尾部斜杠。)
  • cfgFile=/etc/ssh/sshd_config;augtool... incl $cfgfile ls /files/$cfgFile/ 几乎可以做到。祝你好运。

标签: linux bash puppet augeas


【解决方案1】:

默认情况下,Augeas 会加载它知道的所有文件,这可能会很慢。

为防止这种情况发生,您的命令使用--noautoload 绕过自动从镜头加载文件。虽然这使 Augeas 更快,但也意味着它不再了解 /etc/ssh/sshd_config,因此您需要再次手动将此文件映射到 Sshd.lns 镜头,这是使用 --transform Sshd.lns incl /etc/ssh/sshd_config 完成的。

这是另一种可能性(来自augeas-sandbox),可以加载 Augeas 已知的任何文件并绕过其他镜头:

#!/bin/sh

FILE=$1

if [ -z "$FILE" ]; then
  echo "Usage: $0 <FILE>"
  exit 1
fi

augtool -L -i <<EOF
rm /augeas/load/*["$FILE"!~glob(incl) or "$FILE"=~glob(excl)]
load
set /augeas/context /files$FILE
EOF

此脚本将使用自动加载语句,因此您不必指定要使用的镜头,但它只会为您的文件加载您想要的镜头,从而使 Augeas 更快。另外,它设置了/augeas/context,所以你可以使用相对路径:

$ augloadone /etc/ssh/sshd_config
rm : /augeas/load/*["/etc/ssh/sshd_config"!~glob(incl) or "/etc/ssh/sshd_config"=~glob(excl)] 1158
augtool> ls .

【讨论】:

    猜你喜欢
    • 2016-09-03
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-17
    • 1970-01-01
    相关资源
    最近更新 更多