Last active
October 4, 2021 00:03
-
-
Save gabrielsond/56f82b78db3c2b1c8c21c350615031b9 to your computer and use it in GitHub Desktop.
NBMiner Checker Bash Script
This file contains 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 | |
# ----------------------------------------- | |
# NBMiner Checker Script by | |
# Damien Gabrielson <[email protected]> | |
# Requirements: wget curl jq bc | |
# ----------------------------------------- | |
COUNTER=0 | |
MAXBAD=5 | |
STARTSECONDS=15 | |
WAITSECONDS=3 | |
HASHRATE=0 | |
MINERAPI="http://0.0.0.0:22333/api/v1/status" | |
while : | |
do | |
HEADERS=$(wget --spider -S $MINERAPI 2>&1) | |
if [[ $HEADERS == *"200 OK"* ]] ; then | |
TEMPHASHRATE=$(curl -s $MINERAPI | jq -r ".miner.total_hashrate_raw") | |
HASHARRAY=(${TEMPHASHRATE//./ }) | |
let HASHRATE=${HASHARRAY[0]} | |
MEGAHASH=$(bc -l <<<"${HASHRATE}/1000000") | |
printf "%8.6f M\n" "$MEGAHASH" | |
let COUNTER=0 | |
else | |
echo "miner is down" | |
let COUNTER++ | |
fi | |
if [ $COUNTER -eq $MAXBAD ] ; then | |
echo "restart miner" | |
let COUNTER=0 | |
sleep $STARTSECONDS | |
else | |
sleep $WAITSECONDS | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment