]> git.treefish.org Git - bitvalue.git/commitdiff
Improved error handling
authorAlexander Schmidt <alex@treefish.org>
Wed, 8 Nov 2017 18:21:16 +0000 (19:21 +0100)
committerAlexander Schmidt <alex@treefish.org>
Wed, 8 Nov 2017 18:21:16 +0000 (19:21 +0100)
bitvalue

index 7ae88887f93f03bb31773c6dfef60ac41e2e7ab6..9cb4ee96eaf94cb081d4e9964708d3e358e6efac 100755 (executable)
--- a/bitvalue
+++ b/bitvalue
@@ -1,6 +1,7 @@
 #!/bin/bash
 
 CONFIG=~/.bitvaluerc
+HOST=data.bitcoinity.org
 
 TIMESPAN="24h"
 
@@ -42,12 +43,24 @@ fi
 
 source $CONFIG
 
-cat << EOF | gnuplot
+if ! ping -c 1 $HOST >/dev/null 2>&1; then
+    echo "Host $HOST is unreachable!"
+    exit 1
+fi
+
+cat << EOF | gnuplot 2>/dev/null
 set terminal dumb
 set datafile separator ","
 set xdata time
 set timefmt "%Y-%m-%d %H:%M:%S UTC"
 set title "EXCHANGE: $EXCHANGE | TIMESPAN: $TIMESPAN\nZERO RATE: $ZERO_RATE $CURRENCY | ZERO VALUE: $ZERO_VALUE $CURRENCY"
-plot "< wget -q -O - \"https://data.bitcoinity.org/export_data.csv?currency=$CURRENCY&data_type=price&exchange=$EXCHANGE&t=l&timespan=$TIMESPAN\"" \
+plot "< wget -q -O - \"https://$HOST/export_data.csv?currency=$CURRENCY&data_type=price&exchange=$EXCHANGE&t=l&timespan=$TIMESPAN\"" \
      using 1:(\$3/$ZERO_RATE*$ZERO_VALUE) with lines title ""
 EOF
+
+if [ $? -ne 0 ]; then
+    echo "Error while preparing data!" >&2
+    exit 1
+fi
+
+exit 0