Created
December 19, 2018 23:41
-
-
Save tcollins/3fbe8eb313f7f46032ac6232d67b2fa1 to your computer and use it in GitHub Desktop.
Shell script to send to a slack webhook
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/sh | |
### Usage ./send-slack.sh {TITLE} {TEXT} [Optional color hex value] | |
### Example ./send-slack.sh "Your Title Goes Here" "Text goes here" "#ff00ff" | |
TITLE=$1 | |
TEXT=$2 | |
COLOR=${3:-"#007dbc"} | |
INNER_TEMPLATE='{"color":"%s","title":"%s","fallback":"%s","text":"%s"}' | |
INNER_JSON=$(printf "$INNER_TEMPLATE" "$COLOR" "$TITLE" "$TITLE" "$TEXT") | |
TEMPLATE='{"attachments":[%s]}' | |
JSON=$(printf "$TEMPLATE" "$INNER_JSON") | |
curl -X POST -H 'Content-type: application/json' --data "$JSON" https://hooks.slack.com/services/YOUR/INFO-GOES-HERE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment