How do I make an init.d script wait for a startup/shutdown message to appear in a log file, but time out if it takes too long?
tail -f | grep -m 1 should do the trick. There are ways to make the
tail -f time out. And (at least in my opinion) the
tail should terminate with a broken pipe when the
grep stops running, but it doesn't; the
tail -f just keeps running.
Though it's likely I'm doing something wrong, I do have a workaround:
#!/bin/dash (sleep 20 2>/dev/null)& TIMER=$! tail -n 0 -f log --pid $TIMER | \ (R=`grep -cm 1 searchstring`; kill $TIMER 2>/dev/null; exit $R) RESULT=$?