I am trying to create/edit a pushover shell script that can be called from any script or command, and send the output of the script or command to my Pushover account. Following the instructions on this page.
I have placed the following shell script in /usr/local/bin
and added my app token and user tokens.
I am not getting any pushover notifications, or errors after using this command:
john$ ls | pushover.sh 2>&1 | tee file /Users/john/Desktop/results.txt
Contents of the shell script EDITED per Glenn
#!/usr/bin/env bash
# TOKEN INFORMATION
_token='APPTOKEN'
_user='USERTOKEN'
# Bash function to push notification to registered device
push_to_mobile() {
local t="${1:cli-app}"
local m="$2"
[[ -n "$m" ]] && curl -s \
--form-string "token=${_token}" \
--form-string "user=${_user}" \
--form-string "title=$t" \
--form-string "message=$m" \
https://api.pushover.net/1/messages.json
}
I am assuming the conflict is in the first line, possibly in the quoting, but after trying a few different variations haven't had any success.
An example of what is working after trying to debug the above shell script. Obviously this is to just prove that my pushover settings are all in order. This narrows the issue down to the function in the script.
#!/usr/bin/env bash
# TOKEN INFORMATION
_token='xxxx'
_user='yyyy'
_message='test'
# Bash function to push notification to registered device
curl -s \
--form-string "token=${_token}" \
--form-string "user=${_user}" \
--form-string "message=${_message}" \
https://api.pushover.net/1/messages.json
bash: local: `[[': not a valid identifier