When sed
rewrites the log file the server process probably gets an IO error and doesn't try to reopen the log file. I don't know if this approach can work out. sed
definitely doesn't have flags to tweak the way it rewrites files with the -i
flag, and I don't know if the server can be tweaked to be more resilient when appending to the log.
So your best option might be a different approach: save the timestamp of the last error look for errors after that timestamp. Something like this:
ts=
file=console.log
while :; do
if test "$ts"; then
if sed -e "1,/$ts/d" $file | grep -q WARNING; then
sed -e "1,/$ts/d" $file | sendmail ...
ts=$(tail -n 1 $file | cut -f1 -d' ')
fi
else
if grep -q WARNING $file; then
sendmail ... < $file
ts=$(tail -n 1 $file | cut -f1 -d' ')
fi
fi
sleep 15
done
This script is just to give you an idea, it can be improved.