Reputation: 27
So, this script runs for a few hours, but suddenly stops doing its job. According to top it's still running, but it no longer seems to do anything.
WANSTAT=1
LTESTAT=1
tail -f /var/log/messages | grep --line-buffered mwan3 | while read -r INPUT ; do
if [[ "$INPUT" == *"notice mwan3track[]: Interface wan (eth1) is offline" ]]; then
WANSTAT=0
echo "WAN offline"
elif [[ "$INPUT" == *"notice mwan3track[]: Interface lte (3g-lte) is offline" ]]; then
LTESTAT=0
echo "LTE offline"
elif [[ "$INPUT" == *"ifup interface wan (eth1)" ]]; then
WANSTAT=1
elif [[ "$INPUT" == *"ifup interface lte (3g-lte)" ]]; then
LTESTAT=1
fi
if [ $WANSTAT -eq 0 ] && [ $LTESTAT -eq 0 ]; then
echo "All red\n"
elif [ $WANSTAT -eq 0 ]; then
echo "WAN red, LTE green\n"
elif [ $LTESTAT -eq 0 ]; then
echo "LTE red, WAN green\n"
else
echo "All green\n"
fi
done
Upvotes: 0
Views: 78
Reputation: 531125
After a few hours, the logging system closes /var/log/messages
, renames it, and opens a new file with the same name. tail -f
, however, continues to watch the original file, which is no longer written to.
Use tail -F
instead to ensure that you continue to watch the file named /var/log/messages
, regardless of which file that actually is.
Upvotes: 5