Created
September 26, 2016 13:16
-
-
Save chmouel/634b81869259a175ea667b695f56da23 to your computer and use it in GitHub Desktop.
Watch Stock and notify you when it reach a number or lower to a number. When notified it will create a file in /tmp/.reported.up/down.txt rm it or create a cron that delete the old bugger after certain day
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 | |
greater= # set to a price i.e: 20 | |
lower= # set to a price i.e: 10 | |
companystock= # set to a stock sympbol i.e: goog, aapl, fb (will only do for one) | |
[email protected] | |
function report() { | |
local mode=$1 | |
local target=$2 | |
local price=$3 | |
local lockfile=/tmp/.reported.${mode}.txt | |
[[ -e ${lockfile} ]] && exit 0 | |
echo "${price} has becoming ${mode}er than ${target}"|mail -s "${companystock} stock = ${price}" ${email} | |
touch ${lockfile} | |
} | |
function getstock() { | |
local yahoobase=http://download.finance.yahoo.com/d/quotes.csv?s | |
local yahooconv="${yahoobase}=USDEUR=X&f=l1" | |
local stockprice=$(curl -s "${yahoobase}=${companystock}&f=l1"|tr -d '^M') | |
[[ -n ${greater} ]] && (( $(echo "$stockprice >= ${greater}"|bc -l) )) && report high ${higher} ${stockprice} | |
[[ -n ${lower} ]] && (( $(echo "$stockprice <= ${lower}"|bc -l) )) && report low ${lower} ${stockprice} | |
} | |
getstock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment