-
Notifications
You must be signed in to change notification settings - Fork 73
/
pushover
executable file
·70 lines (67 loc) · 2.27 KB
/
pushover
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
###################################################################################
#
# Notify command completion and exit status via pushover and notify-send
#
# uses pushover.sh from https://raw.githubusercontent.com/jnwatts/pushover.sh/master/pushover.sh
#
###################################################################################
#
# Copyright 2015 Jason Antman <[email protected]> <http://www.jasonantman.com>
# Free for any use provided that patches are submitted back to me.
#
# The most recent version of this script is available at:
# <https://github.com/jantman/misc-scripts/blob/master/pushover>
#
###################################################################################
#
# EXAMPLES:
#
# pushover /bin/false
# (sends failure notification)
#
# pushover /bin/true foo bar baz
# (sends success notification)
#
###################################################################################
#
# Version 1.0.1
#
# CHANGELOG:
#
# * 1.0.1 2015-05-11 Jason Antman <[email protected]>
# * swith from env vars for pushover keys to ~/.config/pushover.conf
#
# * 1.0.0 2015-05-11 Jason Antman <[email protected]>
# * Initial public version
#
###################################################################################
if ! which pushover.sh > /dev/null 2>&1; then
>&2 echo "ERROR: pushover.sh not found; please put in path (download from https://raw.githubusercontent.com/jnwatts/pushover.sh/master/pushover.sh)"
exit 1
fi
stime=$(date '+%s')
$@
exitcode=$?
# timer
etime=$(date '+%s')
dt=$((etime - stime))
ds=$((dt % 60))
dm=$(((dt / 60) % 60))
dh=$((dt / 3600))
times=$(printf '%d:%02d:%02d' $dh $dm $ds)
# end timer
if [ "$exitcode" -eq 0 ]
then
pushover.sh -p 0 -t "Command Succeeded" "succeeded in ${times} on $(hostname): $@ (in $(pwd))"
echo "(sent pushover success notification)"
if which notify-send 2>&1 > /dev/null; then
notify-send "Command Succeeded" "succeeded in ${times}: $@ (in $(pwd))"
fi
else
pushover.sh -p 0 -s falling -t "Command Failed" "failed in ${times} (exit $exitcode) on $(hostname): $@ (in $(pwd))"
echo "(sent pushover failure notification)"
if which notify-send 2>&1 > /dev/null; then
notify-send "Command Failed" "failed in ${times} (exit $exitcode): $@ (in $(pwd))"
fi
fi