Created
June 18, 2018 19:44
-
-
Save tsertkov/7c680ab420b7ea3ac60c3f80be18829b to your computer and use it in GitHub Desktop.
Send slack message with preformatted content (e.g. file, command output, etc.) from 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
#!/usr/bin/env bash | |
HOOK_URL="https://hooks.slack.com/services/XXX" | |
FILE="/etc/passwd" | |
MSG="Here is file content as preformatted text:"$'\n```\n'"$(< "$FILE")"$'\n```\n' | |
PAYLOAD="$(jq --raw-input --slurp '{text:.}' <<< "$MSG")" | |
curl \ | |
-X POST \ | |
-H 'Content-type: application/json' \ | |
-d "$PAYLOAD" \ | |
-Ss \ | |
"$HOOK_URL" > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment