Last active
November 27, 2021 07:11
-
-
Save clintar/cd72848c48831def1ffb55eb2fed881a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) | |
MINER_STATUS_RESULT="$?" | |
if [ "$MINER_STATUS_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_HEIGHT=$(echo "$MINER_STATUS" | python3 -c "import sys, json; print(json.load(sys.stdin)['miner_height'])") | |
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)['miner_height'])\" " | |
echo are you sure you have python3 installed? | |
exit 1 | |
fi | |
LATEST_SNAPSHOT=$(curl -s https://us915.s3.amazonaws.com/assets/snaps/snapshot.json) | |
SNAPSHOT_RESULT="$?" | |
if [ "$SNAPSHOT_RESULT" -gt 0 ]; then | |
echo "could not retrieve snapshot height using command : curl -s https://us915.s3.amazonaws.com/assets/snaps/snapshot.json" | |
exit 1 | |
fi | |
SNAPSHOT_HEIGHT=$(echo "$LATEST_SNAPSHOT" | python3 -c "import sys, json; print(json.load(sys.stdin)['height'])") | |
echo "Miner height: "$MINER_HEIGHT"" | |
echo "Snapshot height: "$SNAPSHOT_HEIGHT"" | |
if [ $MINER_HEIGHT -lt $SNAPSHOT_HEIGHT ]; then | |
echo "Miner height ("$MINER_HEIGHT") below snapshot height ("$SNAPSHOT_HEIGHT"). Miner has lost sync." | |
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
save file, name it something like check-miner-sync2.sh
make it executable
chmod +x check-miner-sync2.sh
then run:
crontab -e
and add something like
0,30 * * * * /usr/bin/systemd-cat -t "miner-sync-script" /home/clintar/check-miner-sync2.sh 192.168.7.223
of course changing the path and replacing 192.168.7.223 with your miner's local IP
this will check every half hour if your miner is out of sync below the latest snapshot and run a fast sync on it automatically if so
you can run:
journalctl -u cron.service
to watch what happened when it ran