Last active
June 7, 2018 20:28
-
-
Save gajoseph/9abad6ec96ad20eafe96970cb12c5937 to your computer and use it in GitHub Desktop.
Slack :: Stream any log file to Slack using curl
This file contains hidden or 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 | |
echo "$1, 2 =$2, 3=$3" | |
tail -n0 -F "$1"| while read LINE; do | |
(echo "$LINE" | grep -e "$3") && curl -X POST --silent --data-urlencode \ | |
"payload={ \"channel\": \"#tstpglogs\", \"text\": \"$( sed "s/\"/'/g" <<< $LINE )\"}" "$2"; | |
done | |
### Example: need to find all the queries run by user name starting w/ adhoc | |
### ./tail_slack.sh {pathToLogFile}, {webHookLink}, {searchString} | |
./tail_slack.sh "/logs/pg_log/postgresql-07.log" "https://hooks.slack.com/services/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" "adhoc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment