2017-10-06 10 views
1

소금 상태로 실행하고 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로 단지 경로로 남아있을 싶습니다 .stunnel.log)

EDIT :

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

는 항상 2 선을 차지하고있다 :

your_command | awk '/Name:/ && $2 ~ /\// && $0 ~ /Result: Failed/{print $2}' 
RomanPerekhrest

+0

아니요, 오류 수에 따라 달라 지지만 현실적으로 50+ 회선이 될 수는 있지만 그럴 가능성은 없습니다. – jto

+0

그리고 결과적으로 50+ 에러 라인이 있다면'/ var/log/stunnel.stunnel.log' 라인을 추출하여 출력해야합니까? – RomanPerekhrest

답변

1

단일 명령을 사용하려면 awk가 여기에도 도움이 될 수 있습니다.

your_command | awk '/^Name:/{print $2}' 

편집 : 최신 편집 당으로하면 다음 명령을 시도하십시오 수 있습니다.

salt --state-output=terse -C 'ServerName' state.sls ldapchecker test=True | grep 'Result: Failed' | awk -F':|-' '{print $2}' 
+1

정말로 도움을 주셔서 감사합니다! 여러 개의 '결과 : 실패'출력이있는 경우 확장 가능합니까? @ RanvinderSingh13 – jto

+0

@ jto, 당신을 환영합니다, 그것이 당신을 도왔다 니 기쁩니다. 예, 모든 결과를 선택해야합니다 : 실패한 문자열과 두 번째 열에 경로가 있고 문자열에 Name :이 (가) 있으므로이 조건 중 3 개가 모든 행에서 만나면 비행해야합니다. 같은 질문이 있으면 알려줘. – RavinderSingh13

1

이 코드를 시도

?
+0

이것은 나에게 적합하지 않으며, 단지 ERROR를 출력합니다 : line – jto

+0

grep 앞에 prompt 부분에'2/dev/null' 프롬프트를 추가하고 다시 시도하십시오. 제공된 출력으로 확인한 결과 작동합니다. –