Skip to content

Instantly share code, notes, and snippets.

@rizkysyazuli
Last active June 21, 2021 07:56
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rizkysyazuli/8058dbff52ad773be09de8ac6af8a3bd to your computer and use it in GitHub Desktop.
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
#!/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