The problem is wait for a file to get updated, but not indefinitely. So I want to check if a file has certain contents as -
while ! grep -q $contents /path/to/file
do
sleep $timer
done
along with it I want to check if the timer has expired, say $timer == 0. Here we want the response in the return value so that I can combine with another command using && like
! grep -q $contents /path/to/file && ls someFile
Then the return codes gets fed into if and the need of a temporary variable is removed.
I am currently doing it in this way but I am looking to do it in the while statement itself:
# Wait for 16, 8, 4, 2, 1 seconds each to check for progress
waitTime=16
while ! grep -q $contents $LOG_FILE
do
sleep $waitTime
waitTime=$((waitTime/2))
if [ $waitTime -eq 0 ]
then
break
fi
done