Guest User

Untitled

a guest
Feb 13th, 2020
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.07 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # btsync.sh
  4. #
  5. # bash script that verifies the state of the BTC node, showing data on terminal about its syncing process
  6. #
  7. # Last change @ Sun 10 Feb 2019 01:25
  8. #
  9.  
  10.  
  11.  
  12. bitcoindSynced() {
  13.  
  14. process=bitcoind
  15. pidof -s "$process" > /dev/null 2>&1
  16. status=$?
  17.  
  18. blockCount=$(bitcoin-cli getblockcount)
  19.  
  20. blockChain=$(wget -O - http://blockchain.info/q/getblockcount)
  21.  
  22. if [[ "$status" -eq 0 ]]; then
  23. printf "OK!!! bitcoind is running\n\n"
  24. else
  25. printf "ERROR!!! bitcoind not running\n\n"
  26. exit 1
  27. fi
  28.  
  29. blockCount=`bitcoin-cli getblockcount`
  30.  
  31. if [[ -z "$blockCount" ]] ; then
  32. printf "ERROR!!! Error getting blockcount from bitcoind\n"
  33. exit 1
  34. fi
  35.  
  36. printf "Number of blocks "$blockCount"\n"
  37.  
  38. if [[ -z "$blockChain" ]] ; then
  39. printf "ERROR!!! Error getting blockcount from http://blockchain.info/\n\n"
  40.  
  41. else
  42. blockDiff=$(($blockChain - $blockCount))
  43.  
  44. if [[ ! -z "$blockChain" ]] && [[ ! -z "$blockCount" ]] && [[ ! -z "$blockDiff" ]] ; then
  45. if [[ "$blockDiff" = 0 ]] ; then
  46. echo "up to date"
  47. else
  48. echo ""$blockDiff" blocks behind"
  49. fi
  50. fi
  51.  
  52. perc=$(echo "$blockCount" / "$blockChain" | bc -l)
  53.  
  54. perc=$(echo "$perc"*"100" | bc)
  55.  
  56. perc=$(echo "$perc" | cut -c-5)
  57.  
  58. printf ""$perc" %% Done \n"
  59.  
  60. fi
  61.  
  62. chaintip=$(bitcoin-cli getbestblockhash)
  63.  
  64. printf "\nChaintip: "$chaintip"\n\n"
  65.  
  66. } 2>/dev/null
  67.  
  68.  
  69. function BTC_status_2 () {
  70.  
  71. process="bitcoind"
  72. pidof -s "$process" > /dev/null 2>&1
  73. status=$?
  74.  
  75. if [[ "$status" -eq 0 ]]; then
  76. printf "\n"
  77. # echo "$process is running"
  78. printf "\n"
  79. uname -s -r -v -m -p -i -o
  80. printf "\n"
  81. date
  82. printf "\n"
  83. uptime
  84. printf "\n"
  85. bitcoindSynced
  86. printf "\n"
  87. str1=$(du -sh $HOME/.bitcoin/blocks/ | cut -f 1 )
  88. str2=$(du -sh $HOME/.bitcoin/chainstate/ | cut -f 1 )
  89.  
  90. if [[ -d $HOME/.bitcoin/indexes/ ]] ; then str3=$(du -sh $HOME/.bitcoin/indexes/ | cut -f 1 ) ; fi
  91.  
  92. printf "\nBlockchain storage space:\n${str1}\t ~/.bitcoin/blocks"
  93. printf "\n${str2}\t ~/.bitcoin/chainstate"
  94. if [[ ! -z ${str3} ]] ; then printf "\n${str3}\t ~/.bitcoin/indexes" ; fi
  95. printf "\n\nFull node running for days-hours:minutes:seconds\n$(ps -o etime= -p "$(pidof "$process")")\n\n"
  96. else
  97. echo "$process is NOT running"
  98. fi
  99.  
  100. }
  101.  
  102.  
  103. function Halving () {
  104.  
  105.  
  106. process="bitcoind"
  107. pidof -s "$process" > /dev/null 2>&1
  108. status=$?
  109.  
  110. if [[ "$status" -eq "0" ]]
  111. then
  112.  
  113. block_count=$(bitcoin-cli getblockcount)
  114. block_inc="210000"
  115. era="0"
  116. block_reward="50"
  117.  
  118. for (( blocks=0 ; blocks<$block_count ; blocks=$(($blocks + $block_inc )) )); do
  119.  
  120. ((era++))
  121.  
  122. done
  123.  
  124.  
  125. blocks_left=$(($blocks - $block_count))
  126.  
  127. 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"
  128.  
  129.  
  130. seconds_to_halving=$(( $blocks_left * 60 * 10 ))
  131. now_unix_time=$( date +"%s" )
  132.  
  133. halving_unix_time=$(( $now_unix_time + $seconds_to_halving ))
  134. halving_human_readble_time=$( date -d "@$halving_unix_time" )
  135.  
  136. printf "\nReward-Drop ETA date: %s\n" "$halving_human_readble_time"
  137.  
  138. else
  139. echo "$process NOT running"
  140.  
  141. fi
  142.  
  143. }
  144.  
  145. function dif_adjust () {
  146.  
  147. block_count=$( bitcoin-cli getblockcount )
  148.  
  149. block_tmp1=$(( block_count % 2016 ))
  150.  
  151. block_last_adjust=$(( block_count - block_tmp1 ))
  152.  
  153. block_next_adjust=$(( block_last_adjust + 2016 ))
  154.  
  155. block_to_adjust=$(( block_next_adjust - block_count ))
  156.  
  157. seconds_to_adjust=$(( block_to_adjust * 60 * 10 ))
  158.  
  159. now_unix_time=$( date +"%s" )
  160.  
  161. adjust_unix_time=$(( now_unix_time + seconds_to_adjust ))
  162.  
  163. adjust_human_readble_time=$( date -d "@$adjust_unix_time" )
  164.  
  165. printf "\nNext difficulty adjustment is just %s blocks away at %s\n" "$block_to_adjust" "$adjust_human_readble_time"
  166.  
  167. }
  168.  
  169.  
  170. PROG_NAME=$(basename $0)
  171.  
  172. if [[ -f ~/.bashrc ]] ; then source ~/.bashrc ; fi
  173. if [[ -f ~/.bash_profile ]] ; then source ~/.bash_profile ; fi
  174.  
  175. BTC_status_2
  176.  
  177. Halving
  178.  
  179. dif_adjust
Advertisement
Add Comment
Please, Sign In to add comment