[EN] Post messages to slack from linux

Firstly you need to create webhook url in slack. How to do it you can find at https://www.programmableweb.com/news/how-to-integrate-webhooks-slack-api/how-to/2015/10/20

Secondly you need for example a bash script. My version you can find in gist:

For comfort usage I have copied it to bin folder

cp /current/path/to/slackpost.sh /usr/local/bin/slackpost.sh
chmod +x /usr/local/bin/slackpost.sh

Now you cant access  this script anywhere by typing :

command_with_textual_output | slackpost.sh

Practically you can use it to get info about errors or notifications. Maybe you want to get notification about successfully database backup.

#sh way
echo "Your database backup was created successfully" | slackpost.sh

#python way
os.system("echo 'Your database backup was created successfully' | slackpost.sh")

Personaly I’m using it for notifying me if any of monitored website is offline – https://mindau.de/blog/en/simple-way-monitor-websites-linux/

One thought on “[EN] Post messages to slack from linux”

Leave a Reply

Your email address will not be published. Required fields are marked *