Skip to content

Instantly share code, notes, and snippets.

@BertiKarsunke
Forked from replsv/slack-push-logs.sh
Created March 18, 2019 02:49
Show Gist options
  • Save BertiKarsunke/668804106c4dc7f69c98f8dc1442ec5e to your computer and use it in GitHub Desktop.
Save BertiKarsunke/668804106c4dc7f69c98f8dc1442ec5e to your computer and use it in GitHub Desktop.
Slack log file watcher
#!/bin/bash
SLACK_HOOK_URL="https://hooks.slack.com/services/SOME/SPECIAL/TOKEN"
SLACK_CHANNEL="#production-logs"
tail -n0 -F "$1" | while read LINE; do
(echo "$LINE") && curl -X POST --silent --data-urlencode \
"payload={\"channel\": \"$SLACK_CHANNEL\", \"mrkdwn\": true, \"text\": \"$(echo $LINE | sed "s/\"/'/g") | File: ${1} | Server: $(hostname)\"}" $SLACK_HOOK_URL;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment