Skip to content

Instantly share code, notes, and snippets.

@cyberbutler
Created June 14, 2021 16:43
Show Gist options
  • Save cyberbutler/3bbfee154f37ccbbd4bb18de303d607d to your computer and use it in GitHub Desktop.
Save cyberbutler/3bbfee154f37ccbbd4bb18de303d607d to your computer and use it in GitHub Desktop.
pipe the output of log files to slack
#!/bin/bash
# Author: @cyberbutler
# Description: pipe the output of log files to slack
# Usage:
# _> export SLACKHOOKURL=<your slack hook url here>
# _> tail -f -n0 /var/log/access.log [...other.log] | slack-piper.sh
while read line
do
payload="{\"text\":\"\`\`\`$(echo $line | sed 's/"/\\"/g' | tr -d "\r"| grep -v "==>" | grep -Ev "^$")\`\`\`\"}"
if echo $payload | grep -qv '{"text":"``````"}'; then
curl -X POST -H 'Content-type: application/json' --data "$payload" $SLACKHOOKURL
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment