[nos-bbs] Email Notification of Log Entries?
Niels Ruiter
pd9q at packet-radio.net
Sat Apr 18 01:15:19 EDT 2020
Hi,
I could not sleep, so I was busy with a script that immediately sent an
email when a fwd failed error appeared in the log. Think this works a little
better than the previous script.
Save it to error-check.sh (or something else)
Start it with the & to send it to the background.
./error-check.sh &
Change the variables according to your own needs.
#!/bin/bash
# 18Apr 2020 Niels PD9Q
# Set the current day in a variable to find the right log file. (18Apr20)
now=$(date +"%d%b%y")
# The 'exception to find'
string="fwd failed - Timeout errno 111"
# Open the log and keep a eye on the fwd failed errors
tail -n 0 -F /home/pd9q/jnos/logs/"$now" | \
while read LINE
do
if echo "$LINE" | grep "$string" 1>/dev/null 2>&1
then # the option -E (no empty body), -c (cc-addr)
echo "$LINE" | mailx -E -s "Forward error" pd9q at packet-radio.net
fi
done
# Examples
# Start the script with the & option to send it to the background.
# ./error-check.sh &
# To send a mail to your friends with the forward error use -c
friend at example.com
# mailx -E -s "Forward error" -c friend at example.com pd9q at packet-radio.net
# To point the mail to your jnos smtp server use -S
smtp="jnos.pd9q.ampr.org:25"
# mailx -E -s "Forward error" -S smtp="jnos.pd9q.ampr.org:25"
pd9q at jnos.pd9q.ampr.org
# To attache the log file use -a /path/to/file
# mailx -E -s "Forward error" -a /home/pd9q/jnos/logs/"$now"
pd9q at packet-radio.net
Have fun
73 Niels PD9Q
https://packet-radio.net
-----Original Message-----
From: nos-bbs [mailto:nos-bbs-bounces at lists.tapr.org] On Behalf Of Niels
PD9Q
Sent: Friday, April 17, 2020 9:10 PM
To: nos-bbs at lists.tapr.org
Subject: Re: [nos-bbs] Email Notification of Log Entries?
Hi Charles,
I can get it done with Jnos, but linux can do the trick for you.
Maybe not once there is a log entry. But you can have the log scanned
... We go back an hour and let the log scan for fwd errors. Now you
always know within an hour if there is an fwd error.
# run this crontab entry every hour
0 */1 * * */home/pd9q/jnos/scripts/error-check.sh
error-check.sh
#!/bin/bash
# Fist set the current date for the right log file e.g 17Apr20
now=$(date +"%d%b%y")
# Now let`s have a look in the log at the past hour and find the
'exception' and email it to me.
# mailx -E, if nothing found dont send a NULL body messages. So no empty
messages.
grep "^$(date -d '-1 hour' +'%H')" /home/pd9q/jnos/logs/"$now" | grep -E
"(fwd failed - Timeout errno 111)" \
| mailx -E -s "forward error" pd9q at pd9q.ampr.org
Hope that you find it useful. It is true, if you do not have a busy log,
there is a chance that you will receive the same email for several
hours. You can of course adjust the cronjob to several hours.
73 Niels PD9Q
https://packet-radio.net
Op 16-4-2020 om 19:39 schreef Charles J. Hargrove:
> fwd failed - Timeout errno 111
_______________________________________________
nos-bbs mailing list
nos-bbs at lists.tapr.org
http://lists.tapr.org/mailman/listinfo/nos-bbs_lists.tapr.org
More information about the nos-bbs
mailing list