DEV Community

iainrough
iainrough

Posted on

Post to Slack WebHook from Bash using Curl - Adventures in WSL2 Scripting #2

#!/bin/bash
# URL as supplied in your slack bot
url=https://hooks.slack.com/services/{}/{}/{}

#JSON body
data='{"text": ":interrobang: Unable to do something"}'

sendError()
{
    curl -X \
         POST \
         -H 'Content-type: application/json' \
         --data $data \
         $url
}

#Function that checks something
checkSomething

result=$?
#echo "result: $result"
if [ "$result" != "0" ]; then
    sendError
fi
Enter fullscreen mode Exit fullscreen mode
Bash script that on failure sends slack notice.

The Result in Slack.

Top comments (0)