bmatthewshea
10/24/2017 - 1:45 AM

BASH/CRONTAB - Restart ethminer service if stalled

BASH/CRONTAB - Restart ethminer service if stalled

#!/bin/bash

PATH=$PATH:/usr/bin:/usr/sbin:/var/log/miners:/home/ubuntu/scripts
SECS=$(date +%s)
ETHMINERLOGFILE=/var/log/miners/ethminer.log
ETHMINERRESTART=/var/log/miners/ethminer-restarts.log
idletime=$(expr $SECS - $(date +%s -r $ETHMINERLOGFILE))

echo -n "$(date) - Status check running.. " &>> $ETHMINERRESTART
if [ "$idletime" -gt 300 ]
then
        echo "$(date) - ETHMINER process has been idle for: $idletime seconds" &>> $ETHMINERRESTART
        echo "$(date) - Restarting..." &>> $ETHMINERRESTART
        echo "Last 20 lines of old log:" &>> $ETHMINERRESTART
        echo "" &>> $ETHMINERRESTART
        /usr/bin/tail -n 20 $ETHMINERLOGFILE >> $ETHMINERRESTART
        service ethminer restart
else
        echo "OK" &>> $ETHMINERRESTART
fi