Created
September 5, 2017 22:55
-
-
Save rob-watts/9630f67bfb8bb121f48c39e60bd917a5 to your computer and use it in GitHub Desktop.
PushBullet Shell Script
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/sh | |
function usage { | |
programName=$0 | |
echo "description: A simple shell script to send PushBullet notices" | |
echo "usage: $programName [-t \"type\"] [-s \"subject\"] [-m \"messagel\"]" | |
echo " -t The type (note, file or link) this script only supports 'note'" | |
echo " -s The subject" | |
echo " -m The message" | |
exit 1 | |
} | |
while getopts ":t:s:m:h" opt; do | |
case ${opt} in | |
t) type="$OPTARG" | |
;; | |
s) subject="$OPTARG" | |
;; | |
m) message="$OPTARG" | |
;; | |
h) usage | |
;; | |
\?) echo "Invalid option -$OPTARG" >&2 | |
;; | |
esac | |
done | |
if [[ ! "${type}" || ! "${subject}" || ! "${message}" ]]; then | |
echo "all arguments are required" | |
usage | |
fi | |
read -d '' payLoad << EOF | |
{ | |
"body": "${message}", | |
"title": "${subject}", | |
"type": "${type}" | |
} | |
EOF | |
access_token="YOUR ACCESS TOKEN" | |
sendGridUrl="https://api.pushbullet.com/v2/pushes" | |
statusCode=$(curl \ | |
--write-out %{http_code} \ | |
--silent \ | |
--output /dev/null \ | |
-X POST \ | |
-H 'Content-type: application/json' \ | |
-H "Access-Token: ${access_token}" \ | |
--data "${payLoad}" ${sendGridUrl}) | |
echo ${statusCode} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download & set the execute bit:
chmod +x pb.sh
Then call like this:
./pushbullet.sh -t "note" -s "Ollo" -m "A fake alert from something"