Skip to content

Instantly share code, notes, and snippets.

@gnuton
Last active June 18, 2021 19:28
Show Gist options
  • Save gnuton/1567a337584b7d0e63c7 to your computer and use it in GitHub Desktop.
Save gnuton/1567a337584b7d0e63c7 to your computer and use it in GitHub Desktop.
#!/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