Skip to content

Commit b88662f

Browse files
Jason AntmanJason Antman
Jason Antman
authored and
Jason Antman
committed
add pushover
1 parent 353a627 commit b88662f

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ file.
4949
* __nmap-xml-to-table.php__ - Script to transform multiple nmap XML output files (presumably of the same host/port range with different scan options) into a HTML table
5050
* __print-cmd.sh__ - Simple script to log environment variables and original command for forced ssh commands
5151
* __print-cmd-wrapper.c__ - C wrapper like cmd-wrapper.c, but just echoes back the command that was called
52+
* __pushover__ - script to wrap execution of a command and send [Pushover](https://pushover.net/) and ``notify-send`` notifications about its duration and exit code.
5253
* __quick_cloudtrail.py__ - Python script to parse AWS CloudTrail log JSON files and search for a user, IP, request ID, etc.
5354
* __README.VCS__ - Note on my CVS/SVN to github migration
5455
* __rebuild_srpm.sh__ - Script to rebuild a SRPM 1:1, useful when you want to build a RHEL/CentOS 6 SRPM on a RHEL/CentOS 5 system that doesn't support newer compression (cpio: MD5 sum mismatch)

pushover

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

0 commit comments

Comments
 (0)