-
-
Save erdoukki/d98400455fa71eb900edbf4f2221740e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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