London London - 2 months ago 10
Bash Question

Tailing log until certain time threshold is reached

I'm tailing a log like this:

while [[ ! -n "${ready}" ]]; do
start_info=`grep "Ready" $LOG_FILE`
sleep 10
done


If the log file doesn't have "Ready" inside this goes on forever, how can I make it run for lets say 200 seconds? Like some kind of time threshold.

Thanks

Answer

If I got your question correctly (while [[ ! -n "${ready}" ]]; do is confusing) here is an example how you can check time threshold:

#!/bin/sh

...
timelimit=200
pausetime=10

while [[ -z "${start_info}" ]]; do
  start_info=`grep "Ready" $LOG_FILE`
  sleep $pausetime
  timelimit=$((timelimit - $pausetime))
  if [ $timelimit -le 0 ]; then
    break
  fi  
done
Comments