Shell function to tail a log file for a specific string for a specific time

后端 未结 5 1343
情话喂你
情话喂你 2020-12-29 08:39

I need to the following things to make sure my application server is

  1. Tail a log file for a specific string
  2. Remain blocked until that string is printe
5条回答
  •  星月不相逢
    2020-12-29 09:02

    #!/bin/bash
    tail -f logfile | grep 'certain_word' | read -t 1200 dummy_var
    [ $? -eq 0 ]  && echo 'ok'  || echo 'server not up'
    

    This reads anything written to logfile, searches for certain_word, echos ok if all is good, otherwise after waiting 1200 seconds (20 minutes) it complains.

提交回复
热议问题