Skip to content

Instantly share code, notes, and snippets.

@josue
Last active May 15, 2019 16:17
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 josue/3b83a78cd99016dd828cada2de7c4c3a to your computer and use it in GitHub Desktop.
Save josue/3b83a78cd99016dd828cada2de7c4c3a to your computer and use it in GitHub Desktop.
Slackme - quick send to slack hook
#!/bin/bash
function slackme {
local MESSAGE=${1}
if [ "${MESSAGE}" == "" ]; then
echo "Missing first param: slackme {message}"
return
fi
if [ "${SLACK_HOOK_URL}" == "" ]; then
echo "Missing env var: SLACK_HOOK_URL"
return
fi
local CHANNEL=${2:-"general"}
local USERNAME=${3:-"slackme"}
local ICON_EMOJI=${4:-":robot_face:"}
local JSON_DATA='{"channel":"#'${CHANNEL}'", "username":"'${USERNAME}'", "icon_emoji":"'${ICON_EMOJI}'", "text": "'${MESSAGE}'"}'
curl -s -XPOST -H 'Content-type: application/json' --data "${JSON_DATA}" "${SLACK_HOOK_URL}" >/dev/null
}
# params
SLACK_URL=${SLACK_HOOK_URL:-"https://hooks.slack.com/services/......"}
# main
slackme "$@"
@josue
Copy link
Author

josue commented Jul 12, 2018

Download:

curl -LO https://gist.githubusercontent.com/josue/3b83a78cd99016dd828cada2de7c4c3a/raw/slackme.sh && chmod +x slackme.sh

Usage:

export SLACK_HOOK_URL="https://hooks.slack.com/services/......"

./slackme.sh "hello world" "some-room"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment