Last active
May 6, 2016 06:35
-
-
Save BlinkyStitt/b7bae27388700be4e129ee41a011dcf2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
COINCLIENT=bitcoin-cli | |
function displaytime { | |
local T=$1 | |
local D=$((T/60/60/24)) | |
local H=$((T/60/60%24)) | |
local M=$((T/60%60)) | |
local S=$((T%60)) | |
[[ $D > 0 ]] && printf '%d days ' $D | |
[[ $H > 0 ]] && printf '%d hours ' $H | |
[[ $M > 0 ]] && printf '%d minutes ' $M | |
[[ $D > 0 || $H > 0 || $M > 0 ]] && printf 'and ' | |
printf '%d seconds\n' $S | |
} | |
cnt=$($COINCLIENT getblockcount) | |
hash=$($COINCLIENT getblockhash ${cnt}) | |
timeline=$($COINCLIENT getblock $hash | grep '"time"') | |
ltrimtime=${timeline#*time\" : } | |
newest=${ltrimtime%%,*} | |
secondsago=$(($(date +%s)-$newest)) | |
echo "Last block was $(displaytime $secondsago) ago" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment