Last active
January 28, 2020 00:00
-
-
Save ianlini/648943f4d0d61c58ac8b166ff3c8acb2 to your computer and use it in GitHub Desktop.
Watch a log file and send a Slack message when there is new log.
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/bash | |
set -e | |
LOG_FILE='/var/log/motion/motion.log' | |
WEBHOOK_URL='https://hooks.slack.com/services/...' | |
USERNAME='motion' | |
CHANNEL='camera' | |
function send_slack_message { | |
DATA="payload={\"username\": \"${USERNAME}\", \"channel\": \"${CHANNEL}\", \"text\": \"$1\"}" | |
echo "data: ${DATA}" | |
curl -X POST --data-urlencode "${DATA}" "${WEBHOOK_URL}"; | |
echo "" | |
} | |
send_slack_message 'motion alert started!' | |
tail -n0 -F "${LOG_FILE}" | while read LINE; do | |
send_slack_message "${LINE}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment