Skip to content

Instantly share code, notes, and snippets.

@tcollins
Created December 19, 2018 23:41
Show Gist options
  • Save tcollins/3fbe8eb313f7f46032ac6232d67b2fa1 to your computer and use it in GitHub Desktop.
Save tcollins/3fbe8eb313f7f46032ac6232d67b2fa1 to your computer and use it in GitHub Desktop.
Shell script to send to a slack webhook
#!/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