Last active
November 16, 2016 03:59
-
-
Save RVIRUS0817/6f9cad6cf95543a169e1 to your computer and use it in GitHub Desktop.
shell script
This file contains 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/sh | |
#Incoming WebHooksのURL | |
WEBHOOKURL="https://hooks.slack.com/hogeee" | |
#メッセージを保存する一時ファイル | |
MESSAGEFILE=$(mktemp -t webhooks) | |
#slack 送信チャンネル | |
CHANNEL="#hogeee" | |
#slack 送信名 | |
BOTNAME="hogeee" | |
#slack アイコン | |
FACEICON=":hogeee:" | |
if [ -p /dev/stdin ] ; then | |
#改行コードをslack用に変換 | |
# cat - | tr '\n' '\\' | sed 's/\\/\\n/g' > ${MESSAGEFILE} | |
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\": \"${BOTNAME}\", \"icon_emoji\": \"${FACEICON}\", \"text\": \"${WEBMESSAGE}\" }" ${WEBHOOKURL} >/dev/null | |
#一時ファイルの削除 | |
rm -rf ${MESSAGEFILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment