Created
January 18, 2012 09:26
-
-
Save PhirePhly/1632137 to your computer and use it in GitHub Desktop.
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/sh | |
# Kenneth Finnegan, 2012 | |
# kennethfinnegan.blogspot.com | |
# Posts growp notifications to iOS device using prowl | |
# without using curl or POST feature of wget | |
# Particularly targeted at WRT54G routers | |
# Depends on http://gimi.name/snippets/uploads/urlencode.sed | |
# Which is just a giant list of sed commands to encode to hex | |
# I.e. s/ /%20/g | |
# 2012 01 18: Initial Revision | |
# Insert personal API key here | |
APIKEY=2541XXXX4d77 | |
# Generate some tmp file to dump message into | |
CACHE=/tmp/$$.cache | |
# Make sure you have the urlencode.sed file | |
URLENFILE=/jffs/urlencode.sed | |
if [ ! -e $URLENFILE ] | |
then | |
wget -c http://gimi.name/snippets/uploads/urlencode.sed -O $URLENFILE | |
fi | |
# Set application, event, and dump multiple lines of shell into $CACHE | |
APPLICATION="WRT54G" | |
EVENT="Morning Report" | |
PRIORITY="-1" | |
df /jffs | tail -n 1 | awk '{print "/jffs fs usage " $5}' > $CACHE | |
awk '{print "Load avg: " $1 " "$2 " " $3}' < /proc/loadavg >> $CACHE | |
# URL encode $APPLICATION and $EVENT | |
ENAPP=`echo $APPLICATION | sed -f $URLENFILE` | |
ENEVENT=`echo $EVENT | sed -f $URLENFILE` | |
# URL enode $CACHE using sed, convert new lines to ~ (which are no longer | |
# in $CACHE having been encoded to %7e), and encode ~ as new lines with sed | |
sed -f $URLENFILE <$CACHE | tr '\n' '~' | sed 's/~/%0a/g' > $CACHE.en | |
# Wget a magic URL of everything so far stuck together | |
wget -O - "http://api.prowlapp.com/publicapi/add?apikey=$APIKEY&priority=$PRIORITY&application=$ENAPP&event=$ENEVENT&description=`cat $CACHE.en`" | |
# Clean up after ourselves like a good little shell script | |
rm $CACHE $CACHE.en |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment