2017-02-15 71 views
2

我试图列出正在使用ansible使用超过50%的安装点安装点使用。我在AWK上遇到错误。检查使用ansible

如果我运行此命令单独它的工作原理

df -P | awk '$5 >=90 {print}' 
Filesystem  1024-blocks  Used Available Capacity Mounted on 
tmpfs    2097152 1948868 148284  93% /tmp 

df -P | grep /tmp | awk '$5 >=90 {print}' 
tmpfs    2097152 1948832 148320  93% /tmp 

如果我把同样的命令ansible壳失败

这里:

ansible all -i <hostname>, -m shell -a "df -P | grep /tmp | awk '$5 >=90 {print}'" 
SSH password: 
SUDO password[defaults to SSH password]: 
<hostname> | FAILED | rc=1 >> 
awk: >=90 {print} 
awk:^syntax error 
grep: write error: Broken pipe 

有没有如何做到这一点?有一个更好的方法吗?可能会使用这些因素?

+1

'$ 5'由当前的shell(更换从你在何处运行不可能),逃脱它。 –

回答

0

感谢康斯坦丁·苏沃洛夫你的答案完美。

ansible all -i <hostname>, -m shell -a "df -P | grep /tmp | awk '\$5 >=50 {print}'" 
SSH password: 
SUDO password[defaults to SSH password]: 
<hostname> | SUCCESS | rc=0 >> 
/dev/sda8   944808  55484  840496  7% /var/tmp 
tmpfs    2097152 1858344  238808  89% /tmp 
0

@ user3330284:您可以删除使用grep,并给予一个尝试以下(不,虽然测试过):

ansible all -i <hostname>, -m shell -a "df -P | awk '/\/tmp/{if(\$5 >=50){print}}'"