chore(user/bkmml):Cleanup comment
[BK-2020-03.git] / unitproc / bkgetbtchash
1 #!/bin/bash
2
3 # Date: 2020-03-07T22:18Z; baltakatei>
4
5 # Description: Return latest bitcoin block stats in comma-delimited
6 # line
7
8 # Exit if jq is unavailable or bitcoin-cli getblockcount not available.
9 if ! ( command -v jq 1>/dev/null 2>&1 ) && ! ( bitcoin-cli getblockcount 1>/dev/null 2>&1 ); then echo "Commands jq or bitcoin-cli not available." 1>&2; exit 1; fi
10
11 TIME="$(date +%Y%m%dT%H%M%S%z)"
12 BTC_BESTBLOCKSTATS_JSON="$(bitcoin-cli getblockstats "$(bitcoin-cli getblockcount)" '["height","time","blockhash"]')"
13 BTC_BESTBLOCKCOUNT=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .height')
14 BTC_BESTBLOCKTIME=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .time')
15 BTC_BESTBLOCKHASH=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .blockhash')
16
17 if [ ! -f "$DIR_LOG_PATH" ]; then
18 echo "EVENT_DATE,TARGET_FILEMTIME,DIGEST_ALGO,TARGET_DIGEST,TARGET_FILESIZE,TARGET_FILEPATH" >> "$DIR_LOG_PATH" # print field names in first row
19 fi
20
21 echo "$TIME","$BTC_BESTBLOCKCOUNT","$BTC_BESTBLOCKTIME","$BTC_BESTBLOCKHASH" >> $LOG_PATH;