Last active
December 28, 2019 19:40
-
-
Save whoamiTM/937cfb662ff4281d3189484133848ff3 to your computer and use it in GitHub Desktop.
Script to ping mining rigs and send reboot via Empress + PushOver notification running on Raspberry Pi
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 | |
# Miner Watchdog | |
# Miners Name Hostname | |
miners[0]="miner01;miner01.local" | |
miners[1]="miner02;miner02.local" | |
miners[2]="miner03;miner03.local" | |
miners[3]="miner04;miner04.local" | |
# How often the script checks if rig is frozen (in minutes) | |
freezeInterval=15 | |
# Split miner entry into an array | |
parseMinerData() | |
{ | |
rig=$1 | |
c[0]=$(awk -F ';' '{print $1}' <<< $rig) | |
c[1]=$(awk -F ';' '{print $2}' <<< $rig) | |
echo ${c[@]} | |
} | |
# Function to check if miner is fozen | |
checkMinerFreeze() | |
{ | |
name=$1 address=$2 | |
if ! ping -q -c 1 -W 1 $address >/dev/null 2>&1; then | |
empress -t $name -r >/dev/null 2>&1 | |
echo true && | |
curl -s \ | |
--form-string "token=*" \ | |
--form-string "user=*" \ | |
--form-string "message=Rebooting ${config[0]}" \ | |
https://api.pushover.net/1/messages.json >/dev/null 2>&1 | |
else | |
echo false | |
fi | |
} | |
# Convert Freeze interval from minutes to seconds | |
freezeInterval=$((freezeInterval * 60)) | |
isFrozen=false | |
sleep 10 | |
# Loop | |
while true; do | |
# Check each miner | |
for miner in ${miners[@]}; do | |
# Miner Connection Info | |
config=($(parseMinerData $miner)) | |
isFrozen=$(checkMinerFreeze "${config[0]}" "${config[1]}") | |
echo "[$(date '+%m/%d %T')] Is ${config[0]} frozen: $isFrozen" | |
$isFrozen && echo "[$(date '+%m/%d %T')] Rebooting ${config[0]}" | |
done | |
sleep $freezeInterval # Wait for X seconds before going to beginning of loop | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment