Created
August 27, 2019 00:03
-
-
Save hkennyv/4782f0fb1ceeb60ecf0ecb88c4032c31 to your computer and use it in GitHub Desktop.
tail-slack
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 | |
# tail-slack.sh | |
# author(s): khuynh | |
# description: this script tails log files and posts them to a slack channel | |
# when a new line is appended to the file. It is a modified version of: | |
# https://blog.getpostman.com/2015/12/23/stream-any-log-file-to-slack-using-curl/ | |
# | |
# usage: | |
# $1 - SLACK_URI | |
# ${@:2} = file paths to logfiles | |
URI=$1 | |
echo "$URI" | |
echo "${@:2}" | |
tail -n0 -F -q "${@:2}" | while read LINE; do | |
echo "$LINE" && curl -X POST --silent --data-urlencode \ | |
"payload={\"text\": \"$(echo $LINE | sed "s/\"/'/g")\"}" "$URI"; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment