Skip to content

Instantly share code, notes, and snippets.

@silviuvulcan silviuvulcan/pu.sh
Created Sep 18, 2018

Embed
What would you like to do?
Bash script to send pushover notifications with optional images attachments
#!/bin/bash
APP_TOKEN=""
USER_KEY=""
function usage {
echo "Usage: pu.sh --title "Title" --message "Cool message" [ --file catmeme.jpg ]"
echo
echo "Options:"
echo "-h, --help"
echo " Print detailed usage information"
echo " -t | --title"
echo " Notification title"
echo "-m | --message"
echo " Notification message"
echo "-f | --file"
echo " Image attachment, optional"
exit
}
if [ $# = 0 ]; then
echo "UNKNOWN - missing parameters, see -h, --help"
exit 1
fi
while [ "$1" != "" ]; do
case $1 in
-t | --title ) shift
TITLE=$1
;;
-m | --message ) shift
MESSAGE=$1
;;
-f | --file ) shift
ATTACHMENT=$1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
if [ -z "$TITLE" ]; then
echo "Missing title"
exit 1
fi
if [ -z "$MESSAGE" ]; then
echo "Missing message"
exit 1
fi
if [ -z "$ATTACHMENT" ]; then
curl -s \
--form-string "token=$APP_TOKEN" \
--form-string "user=$USER_KEY" \
--form-string "message=$TITLE" \
--form-string "message=$MESSAGE" \
https://api.pushover.net/1/messages.json
else
curl -s \
--form-string "token=${APP_TOKEN}" \
--form-string "user=${USER_KEY}" \
--form-string "message=${TITLE}" \
--form-string "message=${MESSAGE}" \
-F "attachment=@${ATTACHMENT}" \
https://api.pushover.net/1/messages.json
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.