<p>You could sleep for e.g. 10 minutes after you started bitcoind, and then  do the following:</p>

<ol>
<li><code>bitcoin-cli getblockcount</code>, which is the current height of the node</li>
<li>call <code>getpeerinfo</code>, parse the JSON, take the median of <code>startingheight</code> (how far these nodes are)</li>
<li>If difference &lt; 10, stop bitcoind with <code>bitcoin-cli stop</code> and exit</li>
<li>Sleep 1 minute, repeat </li>
</ol>

<p>Or use something like <a href="https://bitcoin.stackexchange.com/a/21824/4948">this</a> to determine if the last known block is less than an hour old.</p>

CC BY-SA 3.0
2017-11-21T15:59:35.067Z
2017-11-21T15:59:35.067Z
Sjors Provoost
<p>I use bitcoin core infrequently.  I don't want to have it running all the time, but I'm willing to (for now) devote disk space to having it stay current.  I'd like to be relatively current whenever I <em>do</em> start it up, without being weeks behind.</p>

<p>What I'd like to do is:</p>

<ul>
<li>Once a week or so, start bitcoin-core up.</li>
<li>Have it shut down once it's caught up (I guess defined as "when the latest transaction is less than an hour old).</li>
</ul>

<p>I know how to handle step one (via cron/launchd/etc).  What I don't know how to do is step 2: either having it terminate automatically, or using some kind of CLI-command to check the sync status every so often.</p>

<p>If the answer to this is "put in a feature request to bitcoin core", then I'd be looking for workarounds/alternate methods to use until that worked.</p>

<p>For the record, I'm on OSX, but in theory this question applies to all variants of the client.</p>

<p>Any ideas?</p>

CC BY-SA 3.0
2017-11-21T07:29:03.447Z
Bitcoin-core can never complete synchronising since every 8 - 10 min there's an new block.
Tailer
CC BY-SA 3.0
2017-11-21T07:38:04.057Z
Asker specified that he considers to be caught up when he's only one hour behind.
Murch
<bitcoin-core><bitcoin-core-development>
Is there a way to launch bitcoin-core and have it shut down when synchronized?
Gushi
# Is there a way to launch bitcoin-core and have it shut down when synchronized?

(Asked by: username_0 on 2017-11-20)

I use bitcoin core infrequently. I don't want to have it running all the time, but I'm willing to (for now) devote disk space to having it stay current. I'd like to be relatively current whenever I *do* start it up, without being weeks behind.

What I'd like to do is:

* Once a week or so, start bitcoin-core up.
* Have it shut down once it's caught up (I guess defined as "when the latest transaction is less than an hour old).

I know how to handle step one (via cron/launchd/etc). What I don't know how to do is step 2: either having it terminate automatically, or using some kind of CLI-command to check the sync status every so often.

If the answer to this is "put in a feature request to bitcoin core", then I'd be looking for workarounds/alternate methods to use until that worked.

For the record, I'm on OSX, but in theory this question applies to all variants of the client.

Any ideas?

**Tags:** bitcoin-core, bitcoin-core-development

> **Comments:**
> **username_1**: Bitcoin-core can never complete synchronising since every 8 - 10 min there's an new block.  
> **username_2**: Asker specified that he considers to be caught up when he's only one hour behind.  

---

## 1 answers

### Answer by username_3 on 2017-11-21. Score: 0 | Accepted answer

You could sleep for e.g. 10 minutes after you started bitcoind, and then do the following:

1. `bitcoin-cli getblockcount`, which is the current height of the node
2. call `getpeerinfo`, parse the JSON, take the median of `startingheight` (how far these nodes are)
3. If difference < 10, stop bitcoind with `bitcoin-cli stop` and exit
4. Sleep 1 minute, repeat

Or use something like [this](https://bitcoin.stackexchange.com/a/21824/4948) to determine if the last known block is less than an hour old.


---

