Skip to content

Instantly share code, notes, and snippets.

@ankitdbst
Created July 20, 2019 06:41
Show Gist options
  • Save ankitdbst/2925fdab54f594607713b311617d60a1 to your computer and use it in GitHub Desktop.
Save ankitdbst/2925fdab54f594607713b311617d60a1 to your computer and use it in GitHub Desktop.
Tail logs and send to Slack Webhook
#!/bin/bash
# Ref: https://blog.getpostman.com/2015/12/23/stream-any-log-file-to-slack-using-curl/
# define $MAGE_ENV env var in your .profile
tail -n0 -F "$1" | while read LINE; do
(echo "$LINE" | grep -e "$3") && curl -X POST --silent --data-urlencode \
"payload={\"text\": \"$MAGE_ENV $1\\n$(echo $LINE | sed "s/\"/'/g")\"}" "$2";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment