Created
June 14, 2021 16:43
-
-
Save cyberbutler/3bbfee154f37ccbbd4bb18de303d607d to your computer and use it in GitHub Desktop.
pipe the output of log files to slack
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 | |
# 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