DEV Community

loading...

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

iainrough
・1 min read
#!/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.

Discussion (0)