Skip to content

Simple bash script to post slack message from command line

Notifications You must be signed in to change notification settings

amano-takahisa/slack.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

slack-post

Simple slack post interface from terminal with webhook.

Installing

Dependency

This script use jq command to modify json text. Installjq if you don't have jq.

sudo apt install jq

Setup Slack Incomming Webhook

Follow the official configuration manual below to obtain the webhook URL. https://api.slack.com/messaging/webhooks#getting_started

Webhook URL looks something like this: https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX, and export the URL to $SLACK_WHURL with the command below.

export SLACK_WHURL=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

Copy slack_post.sh to your local directory and give the file execute permission.

chmod +x slack_post.sh

Send message

By default, this script will post to default channel selected when you generate webhook URL. You can change default channel from here. https://slack.com/apps/A0F7XDUAZ

  1. Send message
    ./slack_post.sh -t 'Hello from terminal!'
    example1
  2. Send a message received in a pipe.
    echo 'Message via pipe' | ./slack_post.sh
    # if you want to keep your stdout form script,
    echo 'Message via pipe' | tee >(./slack_post.sh)
    example2
  3. Customize message
    # Send different channel
    ./slack_post.sh --channel '#random' --username 'Your boss' --icon_emoji ':sunglasses:'
    example3

If you want to post full-customized message, generate json text and post it with following command.

curl -X POST -H 'Content-type: application/json' --data '{"text":"Done!"}' $SLACK_WHURL

About

Simple bash script to post slack message from command line

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages