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

后端 未结 5 1344
情话喂你
情话喂你 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:00

    You can do it like this:

    start_time=$(date +"%s")
    while true
    do
        elapsed_time=$(($(date +"%s") - $start_time))
        if [[ "$elapsed_time" -gt 1200 ]]; then
            break
        fi
        sleep 1
        if [[ $(grep -c "specific string" /path/to/log/file.log) -ge 1 ]]; then
            break
        fi
    done
    

提交回复
热议问题