Created
April 18, 2018 09:15
-
-
Save Mearman/7015020d44a99d458b64ebc419781b8c to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
| #source: https://gist.github.com/dopiaza/6449505#gistcomment-1627214 | |
| # Usage: slackpost "<webhook_url>" "<channel>" "<username>" "<message>" | |
| # ------------ | |
| webhook_url=$1 | |
| if [[ $webhook_url == "" ]] | |
| then | |
| echo "No webhook_url specified" | |
| exit 1 | |
| fi | |
| # ------------ | |
| shift | |
| channel=$1 | |
| if [[ $channel == "" ]] | |
| then | |
| echo "No channel specified" | |
| exit 1 | |
| fi | |
| # ------------ | |
| shift | |
| username=$1 | |
| if [[ $username == "" ]] | |
| then | |
| echo "No username specified" | |
| exit 1 | |
| fi | |
| # ------------ | |
| shift | |
| text=$* | |
| if [[ $text == "" ]] | |
| then | |
| echo "No text specified" | |
| exit 1 | |
| fi | |
| escapedText=$(echo $text | sed 's/"/\"/g' | sed "s/'/\'/g" ) | |
| json="{\"channel\": \"$channel\", \"username\":\"$username\", \"icon_emoji\":\"ghost\", \"attachments\":[{\"color\":\"danger\" , \"text\": \"$escapedText\"}]}" | |
| curl -s -d "payload=$json" "$webhook_url" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment