Last active
August 19, 2021 17:32
-
-
Save raoulduke/d2e00bb0723b986cddd04c27d525542f to your computer and use it in GitHub Desktop.
Log monitor with email
This file contains 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/bash | |
# Monitor file for changes and send email notification | |
# Usage: ./logmond.sh /path/to/file [email protected] | |
usage() { | |
echo "Usage: ./logmond.sh /path/to/file [email protected]" | |
} | |
if [ "$#" -ne 2 ]; then | |
usage | |
exit 1 | |
fi | |
echo "Monitoring file ($1) for changes, email will be sent to ($2)" | |
cur_line_count="$(wc -l < $1)" | |
while true | |
do | |
new_line_count="$(wc -l < $1)" | |
if [ "$cur_line_count" != "$new_line_count" ] | |
then | |
lines_changed=$((new_line_count - cur_line_count)) | |
changes="$(tail -n $lines_changed $1)" | |
echo "$changes" | s-nail -s "logmond Alert for $1" $2 | |
fi | |
cur_line_count="$new_line_count" | |
sleep 10 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment