• Skip to main content
  • Skip to primary sidebar

JKCrypto

Part 1 : Automatically Restart Mining if Stopped

April 20, 2020 by Anuj Saini 44 Comments

Hi everyone. I have been in to crypto mining now for 5 months and since then I have kept searching for a way to monitor my mining rig. So that I get email notification every time mining gets stopped or I could restart mining automatically in case of a crash. All my searches for this went in vain as I didn’t find any mining monitoring software which could solve my problem. Every mining monitor which I found had limitations like some are paid only, can monitor some particular algo and pool.I could not find a universal monitor that can work with any algo/pool.

Finally, I decided to make one for myself and you all can use it. I have been working on this from the last 2 weeks as I am not a professional programmer however for pros it might be a couple of hours work. At last, the script is working as I wanted.

I have made Windows Powershell script which can

  • monitor the temperature of GPU’s continuously and act accordingly if GPU temperatures go above or below from specified threshold. In case of miner crash, GPUs will stop working and cool down to trigger the script to re-run the miner.
  • monitor for active internet connection, if somehow your internet connection goes down script will automatically connect mining rig to other defined internet connection.
    I live in a remote area so network stability is an issue at my region. I have two different internet connections if one goes down miner will automatically get connected to the other one.
  • in case of a stoppage of mining (restarting mining software, restarting mining rig) you will be notified via email. So that you can act accordingly. If you don’t know your mining rig is not working you will be losing money during that time. This instant email notification will rescue you in that case.
  • if somehow your whole system freeze up then nothing will work not even my script. I have a different solution for that, check part 4 of this tutorial series to know more.

This Mining Monitoring Tutorial consists of 4 articles.

Currently, you are in the first one. In part 1 of the tutorial, you will learn how to automatically restart the mining software in case of a crash.

Check Other Parts Here ( Script is ready for all parts and successfully tested, all I need is time to write the articles. Will be done within a week )

Complete Mining Monitoring Series

Check Here to Know Best altcoin to mine with GTX 1080 Ti

Automatically Restart Mining Software: Steps

1. Create a shortcut of your mining batch file and rename it to jkcrypto

2. Place shortcut in ” C:\Users\All Users\Microsoft\Windows\Start Menu\Programs\Startup “

3. Download script package from here – Part1 and extract it in ” C:\ ” drive.  So all script files will be @ “C:\MinerMonitor\”

automatically restart mining
<#
This Script is Provided By https://jkcrypto.com/
 #>

$Log = "LogFile.log"
$Date = Get-Date
$script:startTime = Get-Date
$failtestcount = 0
$minerrestartno = 0


#set gpu temperature if goes below and above miner software will restart
$temptrig = 35
$tempmaxallow = 80 

#enter total number of gpus currently connected to rig
$totoalgpuno = 7

#Miner Software name in task manager
$minername = "ccminer*"


#Enter miner path if not in startup, otherwise leave as it is
$Minerpath = "C:\Users\All Users\Microsoft\Windows\Start Menu\Programs\Startup\jkcrypto.lnk"


#set time after which script will start
Start-Sleep 180



function GetElapsedTime([datetime]$starttime) 
{
    $runtime = $(get-date) - $starttime
    $retStr = [string]::format("{0} sec(s)", $runtime.TotalSeconds)
    $retStr
}


#to check wheather openhardwaremonitor is running  or not
$ProcessName = "openhardwaremonitor"

    if((get-process $ProcessName -ErrorAction SilentlyContinue) -eq $Null)
    { Start-Process -FilePath ".\OpenHardwareMonitor\OHM.exe" -WindowStyle Minimized}
else
    { echo " openhardwaremonitor is already running " }



#Check GPU load
while($true)
{

$gputemp = Get-WmiObject -namespace root\openhardwaremonitor -class sensor | Where-Object {$_.SensorType -Match "temp" -and $_.Identifier -like "*gpu*"} 


ForEach($GPU In $gputemp) 
     {if($GPU.value -lt $temptrig )
        {$mytest = $GPU.value
        Write-Host $mytest"°C gpu not mininig...temperature seems low"
        #"$Date - Low result obtained $mytest" >> $Log
        $failtestcount = $failtestcount + 1                                      
        }
      else 
        {$mytest = $GPU.value
        Write-Host $mytest"°C gpu is mininig"   
        }
     }


$elapsed = GetElapsedTime $script:startTime
write-host "Mining Since: " $elapsed;




#all nine tests have to get a low result restart
if($failtestcount -gt $totoalgpuno * 3 )
{
    "$Date Miner Restart" >> $Log
    Write-Output " Restarting Miner"
    Stop-Process -name $minername -force
    Start-Process -FilePath $Minerpath
    $minerrestartno = $minerrestartno + 1
    $failtestcount = 0
    $script:startTime = Get-Date


     if($minerrestartno -gt 3)
     {
     Stop-Process -name $minername -force
     Start-Sleep 30
     "$Date Computer Restart" >> $Log
              Restart-Computer -force
     }

}
else
 {
  Write-Host "Everthing Working Fine"
 }





if($GPU.value -gt $tempmaxallow)
    {
    Stop-Process -name $minername -force
    Start-Sleep 300
     Start-Process -FilePath $Minerpath
     $minerrestartno = $minerrestartno + 1
     $failtestcount = 0
     $script:startTime = Get-Date
    "$Date GPU Running Too Hot" >> $Log
    }

Write-Host " "
Write-Host "Starting New Test"
Write-Host " "
Start-Sleep 30
   }

4. Change following in powershell script provided. ( all in beginning )

$temptrig = 35 ( set this threshold if GPU temperature goes below this miner will restart. This depends on region you live, for me 35 is perfect as ambient room temperature is between 10 – 25-degree celsius at my area. I think 35 will work for most of you, or you may tweak it as per need.

  • $tempmaxallow = 80 ( maximum temperature on which gpu can miner. After crossing this threshold mining will be stopped for gpu cool down then restarts.
  • $totoalgpuno = 7 ( total number of gpu connected)
  • $minername = “ccminer*” ( name of miner. Open task manager and look for mining process, check image below to know how to find it, place * after name, * is wild card.)
  • $Minerpath=”C:\Users\All Users\… \Startup\jkcrypto.lnk”

( if you are following steps 1 and 2 then no changes required )

5. If you want this monitoring script get loaded every time after powering on the mining rig then do the following. Move the file “script auto restart” to “C:\Users\All Users\Microsoft\Windows\Start Menu\Programs\Startup\”

6. Done, Part 1 ” restart miner automatically after failure “of this monitoring guide is complete. Will be posting other parts very soon.

I have made this mining monitoring tutorial guide as easy as possible. If you are still facing any issues don’t hesitate to ask via comments below. To appreciate my work you can give this article a share.

Anuj Saini

I write about Crypto mining, trading, referral programs. I have been in the cryptocurrency industry for the last 4 years.

Filed Under: Monitoring Tagged With: auto mining, auto restart, auto script, automated mining script, automatic, automation, batch script, crypto mining, how to guide, mining, mining tracking, monitor miner, monitoring, powershell script, tutorial

Reader Interactions

Comments

  1. bleedingedgeITguru says

    December 5, 2017 at 5:13 pm

    Very cool. Keep them coming. Looking forward to the email alerts. If you can do SMS alerts it would be even better.

    Reply
    • ANUJ SAINI says

      December 5, 2017 at 5:43 pm

      Will be posing email alerts within few hours.
      For SMS alerts check this https://ifttt.com/applets/210655p-send-an-sms-when-an-email-is-received-with-a-specific-subject

      Reply
      • PhiL.D says

        December 9, 2017 at 10:21 pm

        you can try also send alerts via telegram

        Reply
        • ANUJ SAINI says

          December 9, 2017 at 10:26 pm

          ok will check that

          Reply
  2. Cody Gambit says

    December 23, 2017 at 3:53 am

    hi
    I dont understd where and how i can create/copy this script ?(

    Reply
    • ANUJ SAINI says

      December 23, 2017 at 12:15 pm

      Follow the steps,
      “Download script package from here – Part1 and extract it in ” C: ” drive. So all script files will be @ “C:MinerMonitor”
      I will be making video guide for this very soon

      Reply
  3. Imulsion says

    January 7, 2018 at 5:32 am

    Can’t wait for the missing parts! 🙂

    Reply
    • ANUJ SAINI says

      January 7, 2018 at 6:02 pm

      All 4 are done.
      Updating links now

      Reply
  4. Steve Hyde says

    January 15, 2018 at 2:25 am

    Thanks matey, thats a great tool, I’ve been playing around with it a little bit as I wanted it to also stop and restart MSI Afterburner as well… Obviously that wasn’t straight forward as I’ve never written powershell before, but I’ve got it running now. Just the one batch file directly calling the powershell script, as long as the batch file has the same name as the script it works fine.

    @ECHO OFF
    PowerShell.exe -NoProfile -Command “& {Start-Process PowerShell.exe -ArgumentList ‘-NoProfile -ExecutionPolicy Bypass -File “”%~dpn0.ps1″”‘ -Verb RunAs}”
    PAUSE

    Then added these lines to the powershell script

    Stop-Process -name MSI*
    Start-Sleep 5
    Start-Process -FilePath “C:Program Files (x86)MSI AfterburnerMSIAfterburner.exe”

    I’m sure it could be more eloquent… :p

    Reply
    • ANUJ SAINI says

      January 15, 2018 at 2:46 am

      Thanks for sharing.
      Many of readers can’t configure this script so i might create youtube video for this

      Reply
  5. Peter Horsky says

    January 22, 2018 at 12:05 am

    Thanks for this guide! I have one question – do you always change the script when you change coin/miner?

    Reply
    • ANUJ SAINI says

      January 22, 2018 at 12:30 am

      No need to edit code.
      Just add new miner shortcut to startup and name it “jkcrypto”.
      I might create GUI based software for these script in future, but right now very busy in other works

      Reply
      • Peter Horsky says

        January 22, 2018 at 1:46 am

        What I meant is that the script is checking process ccminer*, but for example for GOA coin we use hsrminer_neoscrypt… So the process name is different.

        Reply
        • ANUJ SAINI says

          January 22, 2018 at 12:33 pm

          What can we do to automate here is to use “OR ” and mention all available miners in the script.
          If script find any in running processes than will act accordingly.

          Reply
          • TheDesiKukkadShow says

            January 28, 2018 at 1:39 am

            Hey anuj bro i tried same but couldnt suceed i also have hsr miner problem can u please help me out though team viewer i messaged u fb also please help me out in much problem

          • ANUJ SAINI says

            January 28, 2018 at 1:56 am

            Sorry my bad.Will update post within few minutes.Maximum Nvidia miner are ccminer but not all. you have to change $minername = “ccminer*” with $minername = “hsr*”.

  6. Julien Moody says

    January 22, 2018 at 5:24 pm

    https://uploads.disquscdn.com/images/3ad6b3a4f921f2d4f5b5df7bf254491da6b200c61dc22b255e79ee1b1fc56442.jpg

    Hi, sorry for my english, but I have this error with the script… I don’t find Why 🙁

    Reply
    • ANUJ SAINI says

      January 22, 2018 at 9:11 pm

      Can’t see error in the image.
      Copy paste error message here.
      Many users are facing problem while setting up this script.
      I will create youtube video for this, possibly within a week

      Reply
      • Julien Moody says

        January 23, 2018 at 12:29 am

        I have this :

        openhardwaremonitor is already running
        Get-WmiObject : Le fournisseur ne prend pas en charge l’opération tentée
        Au caractère C:MinerMonitorjkcrypto-minermon.ps1:58 : 12
        + $gputemp = Get-WmiObject -namespace rootopenhardwaremonitor -class s …
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : InvalidOperation : (:) [Get-WmiObject], ManagementException
        + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

        Mining Since: 180,5203705 sec(s)
        Everthing Working Fine

        Starting New Test

        Get-WmiObject : Le fournisseur ne prend pas en charge l’opération tentée
        Au caractère C:MinerMonitorjkcrypto-minermon.ps1:58 : 12
        + $gputemp = Get-WmiObject -namespace rootopenhardwaremonitor -class s …
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : InvalidOperation : (:) [Get-WmiObject], ManagementException
        + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

        Mining Since: 210,6252952 sec(s)
        Everthing Working Fine

        Starting New Test

        Reply
        • QuestionEverything says

          January 23, 2018 at 2:11 am

          Je crois qu’ill ne parle pas francais. English version if it makes it easier. I’m getting a similar message. I’m guessing it’s a permission issue when trying to call hardware monitor for GPU temps. Are you being prompted for admin rights for hardware monitor? If you are and the hardware monitor windows is open, close it. Seems to resolve the issue.

          Get-WmiObject : Provider is not capable of the attempted operation
          At C:MinerMonitorjkcrypto-minermon.ps1:58 char:12
          + $gputemp = Get-WmiObject -namespace rootopenhardwaremonitor -class s …
          + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
          + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

          Reply
          • ANUJ SAINI says

            January 23, 2018 at 3:25 am

            Make changes to openhardwaremonitor as shown in the picture. https://uploads.disquscdn.com/images/d2ab24026b8af73812d876d652137c6cf2b0639b773d7e0866c7c870200e0d95.jpg

          • Julien Moody says

            January 23, 2018 at 3:36 am

            These are already like that

          • ANUJ SAINI says

            January 23, 2018 at 3:50 pm

            The script is working fine on my machine X64 bit Windows OS, consider i am not coder by profession. I will try to replicate this script on new machine and check for error

          • Julien Moody says

            January 23, 2018 at 4:53 pm

            I’m investingating too, I will put the solution here if i found it

          • Julien Moody says

            January 24, 2018 at 1:19 am

            Isn’t possible to use -List or -Quey for this line ?

            $gputemp = Get-WmiObject -Namespace ROOTOpenHardwareMonitor -Class Sensor

            looks like it depends on windows 10 version if i understand :

            https://github.com/openhardwaremonitor/openhardwaremonitor/issues/864

          • ANUJ SAINI says

            January 24, 2018 at 3:34 am

            Can’t help you in coding, don’t know much.
            Few hours back setup this script on my friends computer via team viewer and it work perfectly on his Windows 10 rig.

          • QuestionEverything says

            January 23, 2018 at 4:21 am

            Yes, same here. Already set like the picture.

          • Julien Moody says

            January 24, 2018 at 2:37 am

            I found the solution !

            Just replace OHM 0.8.0 by this one :

            http://openhardwaremonitor.org/files/openhardwaremonitor-v0.8.0.3-alpha.zip

      • Julien Moody says

        January 24, 2018 at 2:39 am

        I found the solution for me !
        Just replace OHM 0.8.0 by this one and set like your picture.

        http://openhardwaremonitor.org/files/openhardwaremonitor-v0.8.0.3-alpha.zip

        Reply
  7. Tom says

    January 23, 2018 at 4:42 pm

    Hi,
    Thanks for sharing your experience and knowledge about mining. I really appreciate this.
    Perhaps this is not the right place to ask you this:
    I’m doing research and at starting point of getting a miner rig myself. Currently using my 1070 for mining while doing research. I would like to ask you if you could make a post about your rig. What motherboard, CPU, RAM, PSU’s and(!) what raisers you used. I thought 6 GPU / ‘normal’ motherboard was the max.
    Thanks!!

    Reply
    • ANUJ SAINI says

      January 23, 2018 at 11:17 pm

      This post is requested many times , hopefully will post very soon.
      This is my rig configuration
      Motherboard : ASUS Z270 A , http://geni.us/SATc
      GPU : Zotac AMP Extreme 1080 TI , http://geni.us/cFEy
      CPU : Intel Celeron G3900 , http://geni.us/szdlE9S
      RAM : 8 GB DDR4 Corsair Vengeance , http://geni.us/b1Z2NSQ
      Hard Disk : 120 GB SSD , http://geni.us/ISfaIxB
      PSU : 1600 Watt EVGA , http://geni.us/jzAwWj9 , 1000 Watt Corsair RMX 1000 , http://geni.us/rrYwn2
      Riser Cables : http://bit.ly/2hsWbpQ
      PSU Extension Cable : http://bit.ly/2i2Azhi
      Cycle Relay Timer : DH48s-s , http://geni.us/1H7A0

      Some other parts also needed like mouse,keyboard, rig frame, etc

      Reply
      • Tom says

        January 24, 2018 at 2:12 am

        Thanks!
        Looking forward to your post.
        I’ve special interest in the risers you’ve selected and why. I’ve seen/read a lot of different power-related issues on those.

        Reply
        • ANUJ SAINI says

          January 24, 2018 at 3:40 am

          These are the best one right now http://bit.ly/2rAKfqa.
          If you can buy them at your local store then do buy otherwise buy from aliexpress but delivery time would be around 15 days.
          Version 7 risers are also good

          Reply
      • Matt White says

        March 4, 2018 at 11:24 am

        Curious why you use a Cycle Relay Timer?? Is it to just restart your rig after a certain amount of continuous mining?? Thanks

        Reply
        • ANUJ SAINI says

          March 8, 2018 at 6:36 pm

          Cycle Relaty time for exhaust fan – It run for 5 minutes after every 15 minutes.
          You can restart your rig using simple windows batch script

          Reply
  8. MIchael Lander says

    January 26, 2018 at 3:06 am

    Its been running for an hour without issues. Thank you so much for your guide.

    Reply
  9. luis ate says

    January 29, 2018 at 10:33 am

    why it didn’t work @ win10 64bit
    the script just start but only blank not working

    Reply
  10. Glenn S Tadeo says

    February 10, 2018 at 11:01 am

    Hi Anuj! What application should i run after doing all the stuff in your guide. Basically it doesnt detect when my GPU is not running or set at Temp Low setting. I tried setting it from 45 and 60deg C.

    Reply
    • ANUJ SAINI says

      February 11, 2018 at 4:58 pm

      Openhardware monitor but it is already added in zip file so should launch automatically. make sure you have followed step 3

      Reply
  11. Derek says

    November 2, 2021 at 11:31 am

    Can this script be altered for restart of GPU if hash rate falls below a set rate?

    Reply
    • Anuj Saini says

      November 2, 2021 at 5:21 pm

      Yes

      Reply
      • Derek says

        November 4, 2021 at 3:52 am

        Can you share the code? This would make life so much easier, as I have been searching for a watchdog option for NBminer for days. Thanks for this by the way. Great work!! Also are you for hire to design custom work?

        Reply
        • Derek says

          November 4, 2021 at 7:15 am

          In this script, it would be nice to add if hash rate falls below x MH/s for x amount of time then reboot miner software or if miner has not gotten a share in x amount of time then reboot miner software.

          Reply
        • Anuj Saini says

          February 6, 2022 at 3:21 am

          sorry for very late reply.
          https://jkcrypto.com/wp-content/uploads/2017/12/MinerMonitor.zip
          No, I am busy in other stuff

          Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Search

Recent

  • Binance Futures Referral Code: JKCRYPTO, Free $500 Welcome Bonus
  • AAX Referral Code: WNvPmcxA2Qo6, Earn 40% Referral Commission
  • OKEx Referral Program : $10 On Signup + Referral Bonus
  • FTX Referral Program : 30% referral commission + 5% fee Discount for Referrals
  • Binance Referral Code: 10186109, 25% Discount

More to See

Binance Futures New Users

Binance Futures Referral Code: JKCRYPTO, Free $500 Welcome Bonus

AAX Referral Code: WNvPmcxA2Qo6, Earn 40% Referral Commission

okex exchange

OKEx Referral Program : $10 On Signup + Referral Bonus

FTX Feature Image

FTX Referral Program : 30% referral commission + 5% fee Discount for Referrals

Bitcoin, Altcoins, Referral Codes, Mining, Crypto News