Author

Topic: Bitcoin from Shell Script. Loading block index duration (Read 1694 times)

legendary
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
Code:
reply=`bitcoin-cli mycommand`
while echo $reply | grep -q "Loading block index..."; do
  sleep 10
  reply=`bitcoin-cli mycommand`
done

But you should probably use a json parser and make something cleaner.
legendary
Activity: 1890
Merit: 1086
Ian Knowles - CIYAM Lead Developer
So there is no more elegant way?

Not that I am aware of (other than using the "blocknotify" approach).

Tried this, but until now I don'g get the error message stored in a variable. Should be solvable though.

Maybe you just need to learn a bit more about scripting?
newbie
Activity: 3
Merit: 0
So there is no more elegant way?
Tried this, but until now I don'g get the error message stored in a variable. Should be solvable though.
legendary
Activity: 1890
Merit: 1086
Ian Knowles - CIYAM Lead Developer
Why don't you just parse the response to check for the error?

(then use your own loop to keep rechecking)
newbie
Activity: 3
Merit: 0
Hey everyone
I start and stop bitcoind inside a shell script. In between I'd like to pass some bitcoin-cli commands. Unfortunatly I have to wait at the beginning of the script for some seconds so that the block index can be loaded. Otherwise the return value for getblockcount (just an example) is error: {"code":-28,"message":"Loading block index..."}
With increasing block number the time to wait increases, too. Hardcoding the wait time with sleep is not an option.
Is there a way to run a command from script if the block index is fully loaded?
Jump to: