AWK Tutorial: When are you expected to produce your next witness block? (STEEMIT)


This is the longest Linux shell command I’ve written!

unix-where-there-is-a-shell-there-is-a-way AWK Tutorial: When are you expected to produce your next witness block? (STEEMIT) awk AWK programming BASH Shell linux linux shell SteemIt

unix-where-there-is-a-shell-there-is-a-way

Last time, we presented the bash/awk command line prints the block number and the number of hours since last time block produced. Here is the version:

docker logs [Replace with your Container ID] | grep "Generated" | awk '{cur=substr($8,2);if (NR>1){print "blocks=",cur-prev," hours=",(cur-prev)*3/3600}prev=cur;}'

Today, we are going to improve the script which allows to print the estimate time till next block to produce. First we need to make sure the gawk is installed via sudo apt-get install gawk. The gawk is the GNU (or improved) version of awk. We need gawk to handle a few datetime functions. After gawk is installed, the awk is often linked to gawk.

Here is the compressed version:

docker logs [container id] | grep "Generated" | gawk -v date="$(date +"%Y-%m-%d-%H-%I-%S")" '{cur=substr($8,2);if (NR>1){print $11,"blocks =",cur-prev," hours =",(cur-prev)*3/3600}last=(cur-prev)*3/60;prev=cur}END{gsub(":", "-",$11);gsub("T","-",$11);split(date,a,"-");split($11,b,"-");t1=mktime(sprintf("%d %d %d %d %d %d 0",a[1],a[2],a[3],a[4],a[5],a[6]));t2=mktime(sprintf("%d %d %d %d %d %d 0",b[1],b[2],b[3],b[4],b[5],b[6]));mins=last-(t1-t2)/60;print "Your next block to produce roughly in",mins,"Minutes.","(",mins/60,"Hours)"}'

The modified version will print the timestamp along each block produced, and in the end if will estimate the number of minutes (and hours) till next block to produce.

docker-steemit-view-blocks AWK Tutorial: When are you expected to produce your next witness block? (STEEMIT) awk AWK programming BASH Shell linux linux shell SteemIt

docker-steemit-view-blocks

It is highly recommended you copy the above command and make it a script e.g. chmod +x view.sh

Support my work, please vote me as a witness. SteemIt Witness Post: Just another Witness

You may also like: 使用AWK来估计您下次出块还需要多久?(SteemIt)

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
477 words
Last Post: Turtle Programming: Fractal Stars, Random, Console, Eraser, SetPC, SetXY, Examples, Wait, Bug Fixes and So much more!
Next Post: Turtle Programming: While Loop, Do/Else Loop and Unit Tests Added

The Permanent URL is: AWK Tutorial: When are you expected to produce your next witness block? (STEEMIT)

Leave a Reply