Skip to content

Instantly share code, notes, and snippets.

@LaggAt
Forked from outadoc/pushbullet.sh
Created October 4, 2017 14:48
Show Gist options
  • Save LaggAt/6125e64fe753fa84f4521475f7de50e3 to your computer and use it in GitHub Desktop.
Save LaggAt/6125e64fe753fa84f4521475f7de50e3 to your computer and use it in GitHub Desktop.
Pushbullet bash script
#!/bin/bash
# from outadoc/pushbullet.sh
# Changes:
# get ACCESS_TOKEN from /etc/pushbullet.conf <LaggAt>
# optional wait for process ending (3rd parameter with PID/executable name), before sending with exit code information <LaggAt>
if [ $# -eq 0 ]; then
echo "Usage: $0 <message> [<title> [pid]]"
exit
fi
MESSAGE=$1
TITLE=$2
if [ $# -lt 2 ] || [ -z "$2" ]; then
TITLE="`whoami`@${HOSTNAME}"
fi
if ! [ -z "$3" ]
then
PID=$3
re='^[0-9]+$'
if ! [[ $3 =~ $re ]] ; then
PID=`pidof -sx $3`
fi
EXITCODE=$(strace -q -e none -e exit_group -p $PID 2>&1 | grep '+++' | tail -n 1 | sed -En 's/[^0-9]*([0-9]{1,})[^0-9]*/\1/gp')
TITLE="$TITLE, PID $PID exited with $EXITCODE"
fi
source /etc/pushbullet.conf
curl -s -u $ACCESS_TOKEN: -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "'"$TITLE"'", "body": "'"$MESSAGE"'"}' >/dev/null 2>&1
@LaggAt
Copy link
Author

LaggAt commented Oct 5, 2017

If you know you're starting a long running task, try this:

./rebuild -j4 ; pushbullet.sh "Done. Exited $?"

./rebuild is the long running process, ";" executeds the right hand command always regardless of the previous command failed, then we send "$?" thru pushbullet, which shows the exit code on your phone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment