Skip to content

Instantly share code, notes, and snippets.

@tsertkov
Created June 18, 2018 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsertkov/7c680ab420b7ea3ac60c3f80be18829b to your computer and use it in GitHub Desktop.
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
#!/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