#!/bin/bash
#
set -eu
WEBHOOKURL="Incoming Webhooks Integration" #你的 incoming webhook url
#
MESSAGEFILE=$(mktemp -t slackweb.XXXXXXX)
trap "
rm ${MESSAGEFILE}
" 0
usage_exit() {
#echo "Usage: $0 [-m message] [-c channel] [-i icon] [-n botname]" 1>&2
echo "Usage: $0 [-m message] [-c channel] [-i icon] [-n botname] [-T title]" 1>&2
exit 0
}
#
CHANNEL=${CHANNEL:-"#lab-01"} #
#
FACEICON=${FACEICON:-":ghost:"}
#
MESSAGE=${MESSAGE:-""}
#
character=$1
case "$character" in
"t1") SITENAME=${SITENAME:-":whale:"} ;;
"t2") SITENAME=${SITENAME:-":construction_worker:"} ;;
"t3") SITENAME=${SITENAME:-":rocket:"} ;;
esac
#
character=$1
case "$character" in
"t1") SITEBOT=${SITEBOT:-"report-bott1"} ;;
"t2") SITEBOT=${SITEBOT:-"report-bott2"} ;;
"t3") SITEBOT=${SITEBOT:-"report-bott3"} ;;
esac
#
#echo "var 'file' == $SITENAME"
if [ -p /dev/stdin ] ; then
#
cat - | tr '\n' '\\' | sed 's/\\/\\n/g' > ${MESSAGEFILE}
else
echo "nothing stdin"
exit 1
fi
WEBMESSAGE='```'`cat ${MESSAGEFILE}`'```'
#
#Incoming WebHooks送信
curl -s -S -X POST --data-urlencode "payload={\"channel\": \"${CHANNEL}\", \"username\": \"${SITEBOT}\", \"icon_emoji\": \"${SITENAME}\", \"text\": \"${MESSAGE}${WEBMESSAGE}\" }" ${WEBHOOKURL} >/dev/null
[Up]常用資訊
[重點文章] 重點文章 [重點文章] 重點文章
2020年4月4日 星期六
[SHELL] 簡化 bash shell 發送訊息到 Slack
[SHELL] 簡化 bash shell 發送訊息到 Slack
簡化 bash shell 發送訊息到 Slack
訂閱:
張貼留言 (Atom)
-
[SHELL] grep 指令使用 or 及 and 查兩個條件以上
-
[Debian] Zabbix 5.0 安裝 中文化
沒有留言:
張貼留言