Skip to content

Instantly share code, notes, and snippets.

@sonots
Last active December 11, 2015 22:39
Show Gist options
  • Save sonots/4671591 to your computer and use it in GitHub Desktop.
Save sonots/4671591 to your computer and use it in GitHub Desktop.
Event Drivern Shell Script :) If something is written in a log file, a processe starts.
PATH="/bin:/usr/bin:/usr/local/bin"
export PATH
FILE="/var/log/syslog"
PATTERN="warn"
SUBJECT="ALERT-LOGWATCH"
MAIL_TO="hogehoge@example.co.jp"
tail -n 1 --follow=name $FILE | while read INPUT; do
echo "$INPUT" | grep "$PATTERN" > /dev/null
RET=$?
if [ "$RET" == "0" ]; then
echo "$INPUT" | mail -s "$SUBJECT" "$MAIL_TO"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment