【问题标题】:Inspec command not printing the memory of a serverInspec 命令不打印服务器的内存
【发布时间】:2020-01-28 18:22:40
【问题描述】:

通过从 inspec.backend.run_command 执行。如果我在 $memory 中使用 awk,它只会打印 CPU 而不是内存。

这是我的代码:

control 'nodes_certs' do  
 impact 0.7               
 title 'nodes_certs'     
 desc 'An optional description...'

nodecert=inspec.backend.run_command("name() { local cpu=$(nproc); local mem=$`(free -g | awk \'/Mem/ {print $2}\')`; echo $cpu; echo $mem ; }; name\'").stdout

print nodecert

end

这是输出:

16

Profile: tests from mem.rb (tests from mem.rb)
Version: (not specified)
Target:  local://

     No tests executed.

【问题讨论】:

    标签: ruby testing awk chef-infra inspec


    【解决方案1】:

    我认为您的 bash 脚本中有错字。如果您使用$(),则不需要反引号。尝试改变:

    $`(free -g | awk \'/Mem/ {print $2}\')`
    

    到

    $(free -g | awk \'/Mem/ {print $2}\')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 2021-05-14
      • 1970-01-01
      • 2013-04-04
      • 2018-04-22
      相关资源
      最近更新 更多