Skip to content

Instantly share code, notes, and snippets.

@michabbb
Last active August 29, 2015 14:27
Show Gist options
  • Save michabbb/a18387753cd8a1019a85 to your computer and use it in GitHub Desktop.
Save michabbb/a18387753cd8a1019a85 to your computer and use it in GitHub Desktop.
Notify a slack channel/user if a process is no longer running -- start with: ./slack_notify.sh <something you are watching for in the process list>
#!/bin/sh
SLACK_HOSTNAME="XXX.slack.com"
SLACK_URL="https://hooks.slack.com/services/XXXXXXXXXX"
SLACK_CHANNEL="@....."
SLACK_BOTNAME="XXXXXX"
OUTPUT=$(ps ax|grep "$1"|grep -v grep|grep -v $0)
if echo "$OUTPUT" | egrep -q "$1" ; then
echo "Still running: $1!"
else
echo "Notify SLack"
curl -X POST --data "payload={\"channel\": \"${SLACK_CHANNEL}\", \"username\": \"${SLACK_BOTNAME}\", \"text\": \"Finished: $1\"}" ${SLACK_URL}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment