Skip to content

Instantly share code, notes, and snippets.

@gajoseph
Last active June 7, 2018 20:28
Show Gist options
  • Save gajoseph/9abad6ec96ad20eafe96970cb12c5937 to your computer and use it in GitHub Desktop.
Save gajoseph/9abad6ec96ad20eafe96970cb12c5937 to your computer and use it in GitHub Desktop.
Slack :: Stream any log file to Slack using curl
#!/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