-
-
Save LaggAt/6125e64fe753fa84f4521475f7de50e3 to your computer and use it in GitHub Desktop.
Pushbullet bash script
This file contains 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 | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.