Bitcoin Forum
December 15, 2024, 01:20:51 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoin from Shell Script. Loading block index duration  (Read 1708 times)
walletfan (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
May 04, 2015, 04:41:57 PM
 #1

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?
CIYAM
Legendary
*
Offline Offline

Activity: 1890
Merit: 1086


Ian Knowles - CIYAM Lead Developer


View Profile WWW
May 04, 2015, 04:46:59 PM
 #2

Why don't you just parse the response to check for the error?

(then use your own loop to keep rechecking)

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
walletfan (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
May 04, 2015, 05:26:50 PM
 #3

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.
CIYAM
Legendary
*
Offline Offline

Activity: 1890
Merit: 1086


Ian Knowles - CIYAM Lead Developer


View Profile WWW
May 04, 2015, 05:32:47 PM
 #4

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?

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
tspacepilot
Legendary
*
Offline Offline

Activity: 1456
Merit: 1081


I may write code in exchange for bitcoins.


View Profile
May 04, 2015, 08:31:20 PM
 #5

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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!