Skip to content

Instantly share code, notes, and snippets.

@RVIRUS0817
Last active November 16, 2016 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RVIRUS0817/6f9cad6cf95543a169e1 to your computer and use it in GitHub Desktop.
Save RVIRUS0817/6f9cad6cf95543a169e1 to your computer and use it in GitHub Desktop.
shell script
#!/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