Inspec命令不打印服务器的内存

问题描述 投票:-2回答:1

通过从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 inspec
1个回答
0
投票

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

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

to

$(free -g | awk \'/Mem/ {print $2}\')
© www.soinside.com 2019 - 2024. All rights reserved.