Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/ash
# This script filters the logs and send it via mail
# Installation on openwrt
#- opkg update && opkg install diffutils
#- install and setup ssmtp (https://fleshandmachines.wordpress.com/2014/09/14/openwrt-automatic-email-sending/)
#- add it to crontab
# Rules
RULES="grep -v info"
MAIL="antonio.aloisio@gmail.com"
# DO NOT TOUCH
OLD_LOG=/tmp/oldlog
NEW_LOG=/tmp/newlog
touch $OLD_LOG
logread > $NEW_LOG
DIFF=$(diff $NEW_LOG $OLD_LOG | grep -v ^--- | grep ^- | $RULES)
if [ -z "$DIFF" ]; then
echo "No changes exit"
exit 0
fi
echo "Mailing logs"
echo -e "Subject: Log activity detected on $HOSTNAME\n\n$DIFF" | ssmtp $MAIL
mv $NEW_LOG $OLD_LOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.