Last Updated: November 15, 2016
·
241
· Lars Van Casteren

Bash - Get the line that doesn't exist yet and do something with it

Quickly keep tabs on a rolling log file and get notified when X happens.
Use tail -F -n 0 (the elusive zero line that does-not-yet-exist!) combined with the ever amazing quick email script from http://caspian.dotconf.net/menu/Software/SendEmail/.

tail -F -n 0 /var/log/messages | while read LOGLINE do [[ "${LOGLINE}" == *"whatever"* ]] && sendEmail -t <your_email> -f <from_mail> -u ${LOGLINE} -s <your_smtp> -m $LOGLINE -q;date;echo "Notification Send For "$LOGLINE done