Last active
February 24, 2018 09:44
-
-
Save tsuyoshicho/4ea9d480d9b9f4e5d9341036a25f9c81 to your computer and use it in GitHub Desktop.
コンソールやシェルスクリプトからのメッセージ通知(日本語OK) ref: https://qiita.com/tsuyoshi_cho/items/a22d895ed67221b8e32e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Event check | |
event="$1" | |
if [ -z "${event}" ];then | |
# fail | |
exit 1 | |
fi | |
# Key | |
# import IFTTT Maker : key | |
# plain | |
# key="$(cat ~/.password-store/Message/ifttt-maker-key)" | |
# password-store style encrypt | |
key="$(gpg --pinentry-mode loopback --no-verbose --quiet --decrypt --output - ~/.password-store/Message/ifttt-maker-key.gpg)" | |
# URL | |
baseurl="https://maker.ifttt.com/trigger" | |
keyurl="with/key" | |
URL="${baseurl}/${event}/${keyurl}/${key}" | |
# notify message | |
arg="$2" | |
if [ -z "${arg}" ];then | |
message="notice from ${HOSTNAME:none}" | |
else | |
message="${arg:none}" | |
fi | |
json=$(echo "{\"value\":\"${message}\"}" | iconv -t UTF-8 | jq -a -M '{value1:(.value|@text),value2:"",value3: ""}') | |
# debug | |
# --verbose | |
# --trace-ascii /dev/stdout | |
# if need insecure SSL/TLS | |
# --insecure | |
curl \ | |
--request POST \ | |
--header "Content-Type: application/json; charset=UTF-8" \ | |
--silent \ | |
--data-binary "${json}" \ | |
$URL | |
# if output is not use, pipe to null | |
# > /dev/null | |
# if output is used, echo "" for treat console | |
echo "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
bash %~dp0notify-slack.sh %* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source notify-maker.sh slack "$*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
bash %~dp0notify-xmpp.sh %* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
URL="http://im.kayac.com/api/post/<username>" | |
# import im.kayac.com API Token | |
api_key=$(cat 秘密鍵) | |
# notify message for XMPP | |
arg="$*" | |
if [ -z "${arg}" ];then | |
message="notice from ${HOSTNAME:none}" | |
else | |
message="${arg:none}" | |
fi | |
message=$(echo "{\"value\":\"${message}\"}" | iconv -t UTF-8 | jq -a -M '.value | @uri' | sed -e 's/"\([^"]*\)"/\1/i' ) | |
# jq' output are quoted "..." | |
# remove using sed regex | |
# debug | |
# --verbose | |
# --trace-ascii /dev/stdout | |
# if need insecure SSL/TLS | |
# --insecure | |
curl \ | |
--request POST \ | |
--silent \ | |
--data-urlencode "password=${api_key}" \ | |
--data-binary "message=${message}" \ | |
$URL > /dev/null | |
# if output is not use, pipe to null | |
# > /dev/null | |
# if output is used, echo "" for treat console | |
# echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment