I run a blockchain node from BSC (Binance smart chain) and I'd like to implement a script that periodically (30s) check if blocks are increasing and if not it would then restart the systemd service.
That's what I've started:
#!/bin/bash
bsc_height=$(curl http://localhost:8545 -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0","id": 0,"method": "eth_blockNumber"}' | awk -F ":" '{ print $4}' | sed 's|["{},]||g')
bsc_height_decimal=$(echo $((bsc_height)))
With that I'm able to get the current block's high through the variable bsc_height_decimal
, let's say the value of it is currently 13083806
. How would a bash loop that checks it every 30s and perform systemctl restart bsc
if the count doesn't increase over this period of time look like?
My idea is to then run this script as a systemd service, or maybe crontab? I'm trying to figure out the best way to do it, what you guys think?
awk
output intosed
.