Skip to content

Instantly share code, notes, and snippets.

@hyukishi
Created February 6, 2019 17:16
Show Gist options
  • Select an option

  • Save hyukishi/6f1ff1cdc19690fc3535671de672b16e to your computer and use it in GitHub Desktop.

Select an option

Save hyukishi/6f1ff1cdc19690fc3535671de672b16e to your computer and use it in GitHub Desktop.
Script for passing stdout to slack messages
#!/bin/bash
# Created by Jeffery Grantham with assistance from Jimmy Burrell on February 5, 2019
# Usage: <command> | slack <channel> <username to display>
# If username is not included, it will default to the username "Admin."
# Designed to pipe stdout in a slack message to any one of the predefined channels
i="$1"
cron="(webhook url here)"
general="(webhook url here)"
random="(webhook url here)"
security="(webhook url here)"
username="$2"
if [ "$i" = "" ]; then
WEBHOOK="$general"
fi
if [ "$i" = "cron" ]; then
WEBHOOK="$cron"
fi
if [ "$i" = "general" ]; then
WEBHOOK="$general"
fi
if [ "$i" = "random" ]; then
WEBHOOK="$random"
fi
if [ "$i" = "security" ]; then
WEBHOOK="$security"
fi
if [ "$username" = "" ]; then
username="Admin"
fi
{ read test; }
curl -H "Content-Type: application/json" --data "{\"username\":\"$username\", \"text\": \" $test \" }" $WEBHOOK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment