diff --git a/slackecho b/slackecho new file mode 100644 index 0000000..c9bb1c1 --- /dev/null +++ b/slackecho @@ -0,0 +1,37 @@ +#!/bin/bash + +# send message to slack +# +# $1 message +# $2 username - optional +# $3 channel - optional +# $4 icon - optional +if [ "$1" = "" ]; then + echo "send message to slack" + echo "slackecho [username] [channel] [icon]" + exit +fi + +SLACKURL="https://hooks.slack.com/services/YOURURL" + +#Setup defaults +if [ "$2" = "" ]; then + SLACKUSER="git-deploy" +else + SLACKUSER="$2" +fi + +if [ "$3" = "" ]; then + SLACKCH="devops" +else + SLACKCH="$3" +fi + +if [ "$4" = "" ]; then + SLACKICON=":robot_face:" +else + SLACKICON="$4" +fi + +#build the post form and send it to the slack url +curl -X POST --data-urlencode 'payload={"channel": "#'$SLACKCH'", "username": "'$SLACKUSER'", "text": "'"$1"'", "icon_emoji": "'$SLACKICON'"}' $SLACKURL -o /dev/null >/dev/null 2>&1