Skip to content

Instantly share code, notes, and snippets.

@clintar
Last active October 28, 2021 00:37
Show Gist options
  • Save clintar/b1f6a201dd32821b23a8f6f579e34061 to your computer and use it in GitHub Desktop.
Save clintar/b1f6a201dd32821b23a8f6f579e34061 to your computer and use it in GitHub Desktop.
check-miner-sync.sh
#!/bin/bash
if [ "$1" = "-h" ] || [ -z "$1" ]; then
echo "Usage: pass miner's IP address to this script"
echo "or pass -h for this message :)"
exit 0
fi
if [ -z ${1+x} ]; then
MINER_IP_USE="$MINER_IP"
else
MINER_IP_USE="$1"
fi
MINER_STATUS=$(curl -s "$MINER_IP_USE"/status.json)
CURL_RESULT="$?"
if [ "$CURL_RESULT" -gt 0 ]; then
echo could not communicate with miner using command: curl -s "$MINER_IP_USE"/status.json
echo are you sure your miner is at this address?
exit 1
fi
MINER_GAP=$(echo "$MINER_STATUS" | python3 -c "import sys, json; print(json.load(sys.stdin)['gap'])")
PYTHON3_RESULT="$?"
if [ "$PYTHON3_RESULT" -gt 0 ]; then
echo could not parse json using command: "echo "$MINER_STATUS" | python3 -c \"import sys, json; print(json.load(sys.stdin)['gap'])\" "
echo are you sure you have python3 installed?
exit 1
fi
#echo "$MINER_GAP"
if [ $MINER_GAP -gt 1000 ]; then
echo Miner gap is "$MINER_GAP". Miner has lost sync. "$MINER_GAP" blocks behind
echo Issuing fast sync command
curl -i -H "Authorization:Basic Ym9iY2F0Om1pbmVy" --request POST http://"$MINER_IP_USE"/admin/fastsync
else
echo Miner at "$MINER_IP_USE" is synced
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment