Skip to content

Instantly share code, notes, and snippets.

@gouf
Last active March 16, 2017 13:45
Show Gist options
  • Select an option

  • Save gouf/0b16e3cc818d87fc04a9d3024e46fe5c to your computer and use it in GitHub Desktop.

Select an option

Save gouf/0b16e3cc818d87fc04a9d3024e46fe5c to your computer and use it in GitHub Desktop.
Notify command execution result to Slack (Incoming Webhooks)
#!/bin/sh
WORK_DIR="/where/to/work/directory"
cd $WORK_DIR || exit # In crontab, it may needs moving into work directory from default directory (home directory)
LS_FILES="$(ls -l file*)" # Wants notify this result
notifyToSlack() {
# In crontab, make sure to the curl command (or other commands) is full path.
/usr/bin/curl -X POST -H 'Content-type: application/json' \
--data "$1" \
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
}
notifyToSlack "{\"text\": \"\`\`\`\n$LS_FILES\n\`\`\`\"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment