diff --git a/errorHandling.sh b/errorHandling.sh new file mode 100755 index 0000000000000000000000000000000000000000..60edc296b009ccc8e49db323d7f6ef3009a2cd2c --- /dev/null +++ b/errorHandling.sh @@ -0,0 +1,54 @@ +if ! curl --silent --head --fail "https://www.kitco.com/charts/livegold.html" >/dev/null; then +echo "gold website down" +else + curl https://www.kitco.com/charts/livegold.html > gold.html + goldBID=$(cat gold.html | grep -E "sp-bid" | sed 's/[^.0-9]*//g') + goldASK=$(cat gold.html | grep -E "sp-ask" | sed 's/[^.0-9]*//g') + goldCHG=$(cat gold.html | grep -E "sp-chg-value" | sed 's/[^.0-9]*//g') + goldCHGpercent=$(cat gold.html | grep -E "sp-chg-percent" | sed 's/[^.0-9]*//g') + $(/opt/lampp/bin/mysql -u root -e"use cw2; insert into gold (goldBit,goldAsk,goldChg,goldChgPercent,dateTime) values ($goldBID,$goldASK,$goldCHG,$goldCHGpercent,default)") + gold=$(cat data.txt | grep -E 'gold' | cut -d ',' -f2,4,6,8,9) + echo "$gold" > gold.csv +fi + +if ! curl --silent --head --fail "https://www.kitcolver.html" >/dev/null; then +echo "silver website down" +else + curl https://www.kitco.com/charts/livesilver.html > silver.html + silverBID=$(cat silver.html | grep -E "sp-bid" | sed 's/[^.0-9]*//g') + silverASK=$(cat silver.html | grep -E "sp-ask" | sed 's/[^.0-9]*//g') + silverCHG=$(cat silver.html | grep -E "sp-chg-value" | sed 's/[^.0-9]*//g') + silverCHGpercent=$(cat silver.html | grep -E "sp-chg-percent" | sed 's/[^.0-9]*//g') + $(/opt/lampp/bin/mysql -u root -e"use cw2; insert into silver (silverBit,silverAsk,silverChg,silverChgPercent,dateTime) values ($silverBID,$silverASK,$silverCHG,$silverCHGpercent,default)") + silver=$(cat data.txt | grep -E 'silver' | cut -d ',' -f2,4,6,8,9) + echo "$silver" > silver.csv +fi + +if ! curl --silent --head --fail "https://www.kitco.com/charts/liveplatinum.html" >/dev/null; then +echo "platinum website down" +else + curl https://www.kitco.com/charts/liveplatinum.html > platinum.html + platinumBID=$(cat platinum.html | grep -E "sp-bid" | sed 's/[^.0-9]*//g') + platinumASK=$(cat platinum.html | grep -E "sp-ask" | sed 's/[^.0-9]*//g') + platinumCHG=$(cat platinum.html | grep -E "sp-chg-value" | sed 's/[^.0-9]*//g') + platinumCHGpercent=$(cat platinum.html | grep -E "sp-chg-percent" | sed 's/[^.0-9]*//g') + $(/opt/lampp/bin/mysql -u root -e"use cw2; insert into platinum (platinumBit,platinumAsk,platinumChg,platinumChgPercent,dateTime) values ($platinumBID,$platinumASK,$platinumCHG,$platinumCHGpercent,default)") + platinum=$(cat data.txt | grep -E 'platinum' | cut -d ',' -f2,4,6,8,9) + echo "$platinum" > platinum.csv +fi + +if ! curl --silent --head --fail "https://www.kitco.com/charts/livepalladium.html" >/dev/null; then +echo "palladium website down" +else + curl https://www.kitco.com/charts/livepalladium.html > palladium.html + palladiumBID=$(cat palladium.html | grep -E "sp-bid" | sed 's/[^.0-9]*//g') + palladiumASK=$(cat palladium.html | grep -E "sp-ask" | sed 's/[^.0-9]*//g') + palladiumCHG=$(cat palladium.html | grep -E "sp-chg-value" | sed 's/[^.0-9]*//g') + palladiumCHGpercent=$(cat palladium.html | grep -E "sp-chg-percent" | sed 's/[^.0-9]*//g') + $(/opt/lampp/bin/mysql -u root -e"use cw2; insert into palladium (palladiumBit,palladiumAsk,palladiumChg,palladiumChgPercent,dateTime) values ($palladiumBID,$palladiumASK,$palladiumCHG,$palladiumCHGpercent,default)") + echo "$palladium" > palladium.csv + date=$(date +%Y-%d-%m) + time=$(date "+%H:%M:%S %p") + echo -e "goldBid,$goldBID,goldAsk,$goldASK,goldChg,$goldCHG,goldChgPercent,$goldCHGpercent,$date $time\nsilverBid,$silverBID,silverAsk,$silverASK,silverChg,$silverCHG,silverChgPercent,$silverCHGpercent,$date $time\nplatinumBid,$platinumBID,platinumAsk,$platinumASK,platinumChg,$platinumCHG,platinumChgPercent,$platinumCHGpercent,$date $time\npalladiumBid,$palladiumBID,palladiumAsk,$palladiumASK,palladiumChg,$palladiumCHG,palladiumChgPercent,$palladiumCHGpercent,$date $time\n" >> data.txt +fi +