Created
November 13, 2012 19:28
-
-
Save cpu/4067836 to your computer and use it in GitHub Desktop.
Watch a URL for a specific phrase, use Pushover to alert with back-off.
This file contains hidden or 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 | |
# Pushover API key | |
TOKEN="PUSHOVER_API_KEY_HERE" | |
# List of device keys to push to | |
KEYS=( KEY_ONE KEY_TWO ) | |
# Url to monitor | |
URL=https://play.google.com/store/devices/details?id=nexus_4_16gb | |
URL_TITLE="Open Nexus4 16gb Product Page" | |
# Phrase to watch for | |
PHRASE="In Stock" | |
#When found, sleep for 5 minutes (to start with) | |
FOUND_SLEEP=$((60*5)) | |
#Increase the FOUND_SLEEP by 2x each 'find' | |
FOUND_SLEEP_FACTOR=2 | |
# Function used to send pushover notification. | |
# Usage: notify $TITLE $MESSAGE | |
function notify() | |
{ | |
for USER in "${KEYS[@]}" | |
do | |
/usr/bin/curl -s \ | |
-F "token=$TOKEN" \ | |
-F "user=$USER" \ | |
-F "title=$1." \ | |
-F "message=$2" \ | |
-F "url=$URL" \ | |
-F "url_title=$URL_TITLE" \ | |
-F "priority=1" \ | |
https://api.pushover.net/1/messages | |
done | |
} | |
function checkURL() | |
{ | |
curl -s $URL | grep -o "$PHRASE" | |
if [ $? -eq 0 ] | |
then | |
notify "Nexus 4 : $PHRASE" "Nexus4 16gb Model status: $PHRASE. Sleeping for $FOUND_SLEEP before resuming monitoring." | |
echo "Sleeping for $FOUND_SLEEP" | |
sleep $FOUND_SLEEP | |
FOUND_SLEEP=$(($FOUND_SLEEP * $FOUND_SLEEP_FACTOR)) | |
fi | |
} | |
echo "Starting URL monitoring." | |
while true | |
do | |
DELAY=$[ ( $RANDOM % 100 ) + 40 ] | |
echo "Checking $URL for $PHRASE" | |
checkURL | |
echo "Sleeping for $DELAY" | |
sleep $DELAY | |
done | |
echo "Goodbye!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment