Skip to content

Instantly share code, notes, and snippets.

@BlinkyStitt
Last active May 6, 2016 06:35
Show Gist options
  • Save BlinkyStitt/b7bae27388700be4e129ee41a011dcf2 to your computer and use it in GitHub Desktop.
Save BlinkyStitt/b7bae27388700be4e129ee41a011dcf2 to your computer and use it in GitHub Desktop.
#!/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