Last active
June 21, 2021 07:56
-
-
Save rizkysyazuli/8058dbff52ad773be09de8ac6af8a3bd to your computer and use it in GitHub Desktop.
[Shell - Server Log to Slack] Sends server log entries to Slack via webhook #webhook #slack #apache #nginx #shell
This file contains 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 | |
tail -n0 -F "$1" | while read LINE; do | |
(echo "$LINE" | grep -e "$3") && curl -X POST --silent --data-urlencode \ | |
"payload={\"text\": \"$(echo $LINE | sed "s/\"/'/g")\"}" "$2"; | |
done | |
# to monitor a single session | |
# ./tail-slack.sh "/var/log/nginx/access-web.log" "https://hooks.slack.com/services/..." " 500 " | |
# to run this in the background | |
# nohup ./tail-slack.sh "/var/log/nginx/access-web.log" "https://hooks.slack.com/services/..." " 500 " > tail-slack.out 2> tail-slack.err < /dev/null & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment