fix(user/gpgfp-noemail):Rename and fix bk-gpgfp-noemail
[BK-2020-03.git] / unitproc / bkgetbtchash
... / ...
CommitLineData
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.
9if ! ( 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
11TIME="$(date +%Y%m%dT%H%M%S%z)"
12BTC_BESTBLOCKSTATS_JSON="$(bitcoin-cli getblockstats "$(bitcoin-cli getblockcount)" '["height","time","blockhash"]')"
13BTC_BESTBLOCKCOUNT=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .height')
14BTC_BESTBLOCKTIME=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .time')
15BTC_BESTBLOCKHASH=$(echo "$BTC_BESTBLOCKSTATS_JSON" | jq '. | .blockhash')
16
17if [ ! -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
19fi
20
21echo "$TIME","$BTC_BESTBLOCKCOUNT","$BTC_BESTBLOCKTIME","$BTC_BESTBLOCKHASH" >> $LOG_PATH;