Error
  • The template for this display is not available. Please contact a Site administrator.

My first attempt at a bitcoin price notification script

So I'm having issues getting notifications about bitcoin prices.  Last night the price dropped and I didn't know because I didn't get any notifications... so I made a simple script on my linux server that runs every minute and checks the price...  if the price drops below a certain value I get a text message (via a email to sms).

 

This script is very simple one but it will text me once a minute until I shut off the script so It will be hard to sleep through another price drop!

 

#!/bin/bash

rm -rvf /tmp/ticke*

#set up email
# Email To ?
EMAIL="MY SMS EMAILThis email address is being protected from spambots. You need JavaScript enabled to view it."">";
MIDEMAIL="MY REGULAR EMAILThis email address is being protected from spambots. You need JavaScript enabled to view it."">";
# other variables
sleep=30
#MUST BE 7 DIGISTS LONG
LOWTARGET=$1
MIDTARGET=$2
HIGHTARGET=$3

while :
do
#get web file
#curl --socks 127.0.0.1:9050 http://data.mtgox.com/api/1/BTCUSD/ticker | sed 's/^...............................................//' | cut -f1 -d"\"" > /tmp/ticker2
curl --socks 127.0.0.1:9050 http://blockchain.info/ticker | grep "USD" | cut -f3 -d":" | cut -f1 -d"," | cut -f2 -d" " > /tmp/ticker2
#copy last price
#LASTPRICE=$(cat /tmp/ticker2 | head -1)
a=$(cat /tmp/ticker2)
echo $a
LASTPRICE=${a%.*}
echo $LASTPRICE

#Run price checks -- LOW
if [ "$LASTPRICE" -lt $LOWTARGET ]
then
echo "low pass"

echo "$LASTPRICE" | mail -s "Low Price Alert!" "$EMAIL" "$MIDEMAIL" "$MESSAGE"
sleep=180
else
echo "Low Price fail"
sleep=30

#Run price checks -- HIGH
if [ "$LASTPRICE" -gt $HIGHTARGET ]
then
echo "high pass"

echo "$LASTPRICE" | mail -s "MID Price Alert" "$EMAIL" "$MIDEMAIL" "$MESSAGE"
sleep=180
else
echo "High Price fail"
sleep=30
#Run price checks -- MIDDLE
if [ "$LASTPRICE" -lt $MIDTARGET ]
then
echo "MID pass"

echo "$LASTPRICE" | mail -s "High Price Alert" "$MIDEMAIL" "$MESSAGE"
sleep=180
else
echo "mid Price fail"
sleep=30

fi

fi

fi


#save price in file for others
#echo "setting web price"
#WEBPRICE=$(echo "$LASTPRICE")
#echo $WEBPRICE
#touch /var/www/madhatt.com/btcprice.html
#echo "$WEBPRICE" > /var/www/madhatt.com/btcprice.html
echo "current sleep time = "$sleep
sleep $sleep
done