Skip to content

Instantly share code, notes, and snippets.

@hkennyv
Created August 27, 2019 00:03
Show Gist options
  • Save hkennyv/4782f0fb1ceeb60ecf0ecb88c4032c31 to your computer and use it in GitHub Desktop.
Save hkennyv/4782f0fb1ceeb60ecf0ecb88c4032c31 to your computer and use it in GitHub Desktop.
tail-slack
#!/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