Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # btsync.sh
- #
- # bash script that verifies the state of the BTC node, showing data on terminal about its syncing process
- #
- # Last change @ Sun 10 Feb 2019 01:25
- #
- bitcoindSynced() {
- process=bitcoind
- pidof -s "$process" > /dev/null 2>&1
- status=$?
- blockCount=$(bitcoin-cli getblockcount)
- blockChain=$(wget -O - http://blockchain.info/q/getblockcount)
- if [[ "$status" -eq 0 ]]; then
- printf "OK!!! bitcoind is running\n\n"
- else
- printf "ERROR!!! bitcoind not running\n\n"
- exit 1
- fi
- blockCount=`bitcoin-cli getblockcount`
- if [[ -z "$blockCount" ]] ; then
- printf "ERROR!!! Error getting blockcount from bitcoind\n"
- exit 1
- fi
- printf "Number of blocks "$blockCount"\n"
- if [[ -z "$blockChain" ]] ; then
- printf "ERROR!!! Error getting blockcount from http://blockchain.info/\n\n"
- else
- blockDiff=$(($blockChain - $blockCount))
- if [[ ! -z "$blockChain" ]] && [[ ! -z "$blockCount" ]] && [[ ! -z "$blockDiff" ]] ; then
- if [[ "$blockDiff" = 0 ]] ; then
- echo "up to date"
- else
- echo ""$blockDiff" blocks behind"
- fi
- fi
- perc=$(echo "$blockCount" / "$blockChain" | bc -l)
- perc=$(echo "$perc"*"100" | bc)
- perc=$(echo "$perc" | cut -c-5)
- printf ""$perc" %% Done \n"
- fi
- chaintip=$(bitcoin-cli getbestblockhash)
- printf "\nChaintip: "$chaintip"\n\n"
- } 2>/dev/null
- function BTC_status_2 () {
- process="bitcoind"
- pidof -s "$process" > /dev/null 2>&1
- status=$?
- if [[ "$status" -eq 0 ]]; then
- printf "\n"
- # echo "$process is running"
- printf "\n"
- uname -s -r -v -m -p -i -o
- printf "\n"
- date
- printf "\n"
- uptime
- printf "\n"
- bitcoindSynced
- printf "\n"
- str1=$(du -sh $HOME/.bitcoin/blocks/ | cut -f 1 )
- str2=$(du -sh $HOME/.bitcoin/chainstate/ | cut -f 1 )
- if [[ -d $HOME/.bitcoin/indexes/ ]] ; then str3=$(du -sh $HOME/.bitcoin/indexes/ | cut -f 1 ) ; fi
- printf "\nBlockchain storage space:\n${str1}\t ~/.bitcoin/blocks"
- printf "\n${str2}\t ~/.bitcoin/chainstate"
- if [[ ! -z ${str3} ]] ; then printf "\n${str3}\t ~/.bitcoin/indexes" ; fi
- printf "\n\nFull node running for days-hours:minutes:seconds\n$(ps -o etime= -p "$(pidof "$process")")\n\n"
- else
- echo "$process is NOT running"
- fi
- }
- function Halving () {
- process="bitcoind"
- pidof -s "$process" > /dev/null 2>&1
- status=$?
- if [[ "$status" -eq "0" ]]
- then
- block_count=$(bitcoin-cli getblockcount)
- block_inc="210000"
- era="0"
- block_reward="50"
- for (( blocks=0 ; blocks<$block_count ; blocks=$(($blocks + $block_inc )) )); do
- ((era++))
- done
- blocks_left=$(($blocks - $block_count))
- printf "\nBitcoin is in reward era %s and current block height is %s blocks. And there are %s blocks left for halving.\n" "$era" "$block_count" "$blocks_left"
- seconds_to_halving=$(( $blocks_left * 60 * 10 ))
- now_unix_time=$( date +"%s" )
- halving_unix_time=$(( $now_unix_time + $seconds_to_halving ))
- halving_human_readble_time=$( date -d "@$halving_unix_time" )
- printf "\nReward-Drop ETA date: %s\n" "$halving_human_readble_time"
- else
- echo "$process NOT running"
- fi
- }
- function dif_adjust () {
- block_count=$( bitcoin-cli getblockcount )
- block_tmp1=$(( block_count % 2016 ))
- block_last_adjust=$(( block_count - block_tmp1 ))
- block_next_adjust=$(( block_last_adjust + 2016 ))
- block_to_adjust=$(( block_next_adjust - block_count ))
- seconds_to_adjust=$(( block_to_adjust * 60 * 10 ))
- now_unix_time=$( date +"%s" )
- adjust_unix_time=$(( now_unix_time + seconds_to_adjust ))
- adjust_human_readble_time=$( date -d "@$adjust_unix_time" )
- printf "\nNext difficulty adjustment is just %s blocks away at %s\n" "$block_to_adjust" "$adjust_human_readble_time"
- }
- PROG_NAME=$(basename $0)
- if [[ -f ~/.bashrc ]] ; then source ~/.bashrc ; fi
- if [[ -f ~/.bash_profile ]] ; then source ~/.bash_profile ; fi
- BTC_status_2
- Halving
- dif_adjust
Advertisement
Add Comment
Please, Sign In to add comment