Skip to content

Instantly share code, notes, and snippets.

@zaemyung
Created April 12, 2017 04:20
Show Gist options
  • Save zaemyung/97f8262f643d01a11aabd84feddbc492 to your computer and use it in GitHub Desktop.
Save zaemyung/97f8262f643d01a11aabd84feddbc492 to your computer and use it in GitHub Desktop.
Post a notification to slack with the username as the name of the current directory
#!/bin/bash
function post_to_slack () {
PROC_PATH=${PWD##*/}
SLACK_MESSAGE="\`\`\`$1\`\`\`"
SLACK_URL=https://hooks.slack.com/services/{hook_address_here}
case "$2" in
INFO)
SLACK_ICON=':monkey_face:'
;;
WARNING)
SLACK_ICON=':warning:'
;;
ERROR)
SLACK_ICON=':bangbang:'
;;
*)
SLACK_ICON=':slack:'
;;
esac
curl -X POST --data "payload={\"username\":\"${PROC_PATH}\", \"icon_emoji\":\"${SLACK_ICON}\", \"text\":\"${SLACK_MESSAGE}\"}" ${SLACK_URL}
}
post_to_slack "Process has just ended!" "INFO"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment