Bitcoin Forum
May 05, 2024, 11:22:28 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoin from Shell Script. Loading block index duration  (Read 1673 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?
1714908148
Hero Member
*
Offline Offline

Posts: 1714908148

View Profile Personal Message (Offline)

Ignore
1714908148
Reply with quote  #2

1714908148
Report to moderator
The grue lurks in the darkest places of the earth. Its favorite diet is adventurers, but its insatiable appetite is tempered by its fear of light. No grue has ever been seen by the light of day, and few have survived its fearsome jaws to tell the tale.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714908148
Hero Member
*
Offline Offline

Posts: 1714908148

View Profile Personal Message (Offline)

Ignore
1714908148
Reply with quote  #2

1714908148
Report to moderator
1714908148
Hero Member
*
Offline Offline

Posts: 1714908148

View Profile Personal Message (Offline)

Ignore
1714908148
Reply with quote  #2

1714908148
Report to moderator
1714908148
Hero Member
*
Offline Offline

Posts: 1714908148

View Profile Personal Message (Offline)

Ignore
1714908148
Reply with quote  #2

1714908148
Report to moderator
CIYAM
Legendary
*
Offline Offline

Activity: 1890
Merit: 1075


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: 1075


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: 1076


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!