Continuing the discussion from Send email on firewall warning:
So Ihad to make some slight mods to the scripts files, mostly the way that they sended the emails wasn't correct and provoked that emails were rejected by the server (this is because on how smtp behaves, it will try to send the email as root@(router hostname).(domain extension) typically as root@openwrt.lan and not the email as specified in the config.
The files will be something like this:
/etc/ssmtp/logWatch.sh
#!/bin/sh
# 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="destinationemailaddress@theirdomain.com"
# DO NOT TOUCH
OLD_LOG=/tmp/oldlog
NEW_LOG=/tmp/newlog
if [ -f $OLD_LOG ]; then
logread > $NEW_LOG
else
touch $OLD_LOG
logread > $NEW_LOG
fi
DIFF=$(diff $NEW_LOG $OLD_LOG | grep -v ^--- | grep ^- | $RULES)
echo Starting email sender
if [ -z "$DIFF" ]; then
echo "No changes to be send exiting"
mv $NEW_LOG $OLD_LOG
exit 0
else
{
echo To: $MAIL
echo Subject: Log activity detected on $HOSTNAME
echo
echo $DIFF
} | sendmail -F"OpenWrt" -t
mv $NEW_LOG $OLD_LOG
fi
/etc/init.d/emailafterreboot
#!/bin/sh /etc/rc.common
# Example script
# Copyright (C) 2007 OpenWrt.org
START=99
STOP=100
RULES="grep -v info"
MAIL=destinationemailaddress@theirdomain.com
OLD_LOG=/tmp/oldlog
NEW_LOG=/tmp/newlog
if [ -f $OLD_LOG ]; then
logread > $NEW_LOG
else
touch $OLD_LOG
logread > $NEW_LOG
fi
DIFF=$(diff $NEW_LOG $OLD_LOG | grep -v ^--- | grep -v ^- | $RULES)
start() {
echo Starting email sender after reboot
if [ -z "$DIFF" ]; then
echo "No changes to be send exiting"
mv $NEW_LOG $OLD_LOG
exit 0
else
{
echo To: $MAIL
echo Subject: Log activity detected on $HOSTNAME
echo
echo $DIFF
} | sendmail -F"OpenWrt" -t
mv $NEW_LOG $OLD_LOG
fi
}
stop() {
echo Stoping email sneder after reboot
# commands to kill application
if [ -f $NEW_LOG ]; then
mv $NEW_LOG $OLD_LOG
else
exit 0
fi
}
boot() {
echo Starting email sender after reboot
if [ -z "$DIFF" ]; then
echo "No changes to be send exiting"
mv $NEW_LOG $OLD_LOG
exit 0
else
{
echo To: $MAIL
echo Subject: Log activity detected on $HOSTNAME
echo
echo $DIFF
} | sendmail -F"OpenWrt" -t
mv $NEW_LOG $OLD_LOG
fi
}