bash - parsing a logfile for error messages -
i'm trying write bash command able set variable (exitstatus) based on scanning of log file specific pattern.
inside log file, many error messages can present. problem 1 error message written on 2 lines. example:
error 77: invalid record detected @ position 88332: bad alignment detected [ird-21] error 77: invalid record detected @ position 88333: bad alignment detected [ird-21] error 77: invalid record detected @ position 88334: bad alignment detected [ird-21] error 77: invalid record detected @ position 88335: bad alignment detected [ird-21] error 88: bad format in string @ record 287 [syn-44] error 88: bad format in string @ record 288 [syn-44] error 88: bad format in string @ record 289 [syn-44] error 73: invalid table spec or stub @ record 1022 [invt-33]
if log file contains messages related error 77 [ird-21], or if there no errors @ it's fine, exitstatus remains 0. otherwise, exitstatus set 2.
i've been trying find , grep fact error message can spread on 2 lines destroying efforts. put, i'd inquire shell: "hey, bash, log file contains other errors ird-21?, if so, raise error".
also, have no command on log file format, comes our client.
any ideas on how this?
if want know if there's word error
followed other 77
, can (with gnu grep):
exitstatus=$(grep -qp 'error (?!77)' sample.log && echo 2 || echo 0)
bash grep find
No comments:
Post a Comment