我正在運行鹽狀態並使用grep來檢索任何失敗的檢查。在默認情況下,輸出下面的文本每一次失敗鹽:如何減少grep命令的輸出?
ERROR: Minions returned with non-zero exit code
我希望削減從我的命令,這個輸出,這樣我可以用實際的故障(例如,其中的細節檢查失敗),以輸出到.html文件將用於顯示我們的環境的當前狀態。
這裏是我的命令:
salt --state-output=terse -C 'ServerName' state.sls ldapchecker test=True | grep 'Result: Failed'
這裏是輸出:
ERROR: Minions returned with non-zero exit code
Name: /var/log/stunnel.stunnel.log - Function: file.exists - Result: Failed
我想會留下失敗的檢查(在/ var /日誌/安全通道的人的路.stunnel.log)
編輯:由於這裏要求是輸出:
salt --state-output=terse -C 'BCA-AJT-LD-01' state.sls ldapchecker test=True 2>/dev/null
BCA-AJT-LD-01:
Name: /opt/checkservices.sh - Function: file.managed - Result: Clean
Name: /var/log/openldap/slapd.log - Function: file.exists - Result: Clean
Name: /var/log/stunnel.stunnel.log - Function: file.exists - Result: Failed
Name: /etc/openldap/ldap.conf - Function: file.exists - Result: Clean
Name: /etc/openldap/certs/cert8.db - Function: file.exists - Result: Clean
Name: /etc/openldap/certs/key3.db - Function: file.exists - Result: Clean
Name: /etc/openldap/certs/secmod.db - Function: file.exists - Result: Clean
Name: /etc/stunnel/stunnel.conf - Function: file.exists - Result: Clean
Name: /etc/stunnel/stunnel.pem - Function: file.exists - Result: Clean
Name: /etc/rsyslog.conf - Function: file.exists - Result: Clean
Name: salt-master - Function: service.running - Result: Clean
Name: /opt/serverdetails/serverdetails.sh - Function: file.exists - Result: Clean
Name: /opt/serverdetails/servers_list - Function: file.exists - Result: Clean
Name: /opt/serverdetails/style.css - Function: file.exists - Result: Clean
Name: /opt/serverdetails/test.htm - Function: file.exists - Result: Clean
Name: /opt/serverversions/serverversions.sh - Function: file.exists - Result: Clean
Name: /opt/serverversions/servers_list - Function: file.exists - Result: Clean
Name: /opt/serverversions/style.css - Function: file.exists - Result: Clean
Name: /opt/serverversions/test.htm - Function: file.exists - Result: Clean
Name: rsyslog - Function: service.running - Result: Clean
Name: salt-minion - Function: service.running - Result: Clean
Name: sshd - Function: service.running - Result: Clean
Name: ntpd - Function: service.running - Result: Clean
Summary
-------------
Succeeded: 22
Failed: 1
-------------
Total states run: 23
是它始終佔據2行? – RomanPerekhrest
不,它會根據有多少錯誤而有所不同,實際上可能是50多行,但這不太可能。 – jto
,如果出現50 +以上的錯誤行,是否應該提取並打印'/ var/log/stunnel.stunnel.log'行? – RomanPerekhrest