Last active
March 8, 2018 15:44
-
-
Save hannesa2/2a898ad6b08db5aa8a86b3dce28f7887 to your computer and use it in GitHub Desktop.
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 | |
clientId=$(hostname) | |
topic="no topic" | |
payload="no payload" | |
title="$(hostname) Detection" | |
startMillis=$(date +'%s') | |
startDate=$(date '+%Y-%m-%d %H:%M:%S') | |
SERVER_KEY=GCM-SERVERKEY # you find it in firebase console | |
while getopts ":c:p:w:q:t:" opt; do | |
case $opt in | |
c) clientId="$OPTARG" | |
;; | |
p) payload="$OPTARG" | |
;; | |
t) topic="$OPTARG" | |
;; | |
\?) echo "Invalid option -$OPTARG" >&2 | |
;; | |
esac | |
done | |
eval "action=''" | |
eval "notification='\"notification\":{\"body\":\"$payload\",\"title\":\"$title\"$action}'" | |
eval "data='{\"to\" : \"/topics/${topic}\", \"data\":{\"message\":\"$payload\",\"start\": $startMillis,\"date\":\"$startDate\",\"client\":\"$clientId\"}, $notification}'" | |
echo $data > /tmp/json | |
eval "cmd='curl -X POST --header \"Authorization: key=$SERVER_KEY\" --Header \"Content-Type: application/json\" https://fcm.googleapis.com/fcm/send -d \"@/tmp/json\"'" | |
result=$(curl -X POST --header "Authorization: key=$SERVER_KEY" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "@/tmp/json") | |
echo $result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./sendNotification.sh -t test -p myPayload
fires something like