[Python] Looking for keyword 'ERROR' but omit lines with 'ERROR' and '/etc/passwd'

Discussão em 'Python' iniciado por Stack, Agosto 5, 2025.

  1. Stack

    Stack Membro Participativo

    I'm writing a script to look for keywords like ERROR but to omit lines that has ERROR followed by a string /etc/passwd, but the user does not exist, while no InResponseTo was expected, and while no InResponseTo was expected on the same line.

    Here is the script

    with open(PATH, 'r') as file:

    lines = file.readlines()

    for row in lines:

    if ('OutOfMemoryError' in row or
    'DEADLINE_EXCEEDED' in row or
    'CommandTimeoutException' in row or
    'ERROR' in row or
    'FATAL' in row
    ):

    if not ('win.ini' in row or
    '/etc/passwd' in row or
    'but the user does not exist' in row or
    'while no InResponseTo was expected' in row or
    'com.onelogin.saml2.Auth processResponse error. invalid_response'
    ):

    print(row, flush=True)


    I just want my script to print the lines that has OutOfMemoryError DEADLINE_EXCEEDED CommandTimeoutException ERROR without /etc/passwd.

    But it's printing ERROR with /etc/passwd.

    I think my if and if not operation is not correct

    Continue reading...

Compartilhe esta Página