Skip to content

Instantly share code, notes, and snippets.

@stekhn
Last active September 3, 2020 08:43
Show Gist options
  • Save stekhn/188d7183fd813214a995fa5573ae5eb5 to your computer and use it in GitHub Desktop.
Save stekhn/188d7183fd813214a995fa5573ae5eb5 to your computer and use it in GitHub Desktop.
Stream a log file (Apache, Ngix etc.) to a Slack channel with webhooks. From the Postman blog: http://blog.getpostman.com/2015/12/23/stream-any-log-file-to-slack-using-curl/
#!/bin/bash
tail -n0 -F "$1" | while read LINE; do
(echo "$LINE" | grep -e "$3") && curl -X POST --silent --data-urlencode \
"payload={\"text\": \"$(echo $LINE | sed "s/\"/'/g")\"}" "$2";
done
@stekhn
Copy link
Author

stekhn commented Sep 5, 2016

Usage example: ./log-to-slack "/var/log/httpd/access_log" "https://hooks.slack.com/services/T040QAYN4/B29A..." "404"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment