Skip to content

Instantly share code, notes, and snippets.

@clintar
Created October 28, 2021 04:54
Show Gist options
  • Save clintar/af07d87f28b04e01183a8b8569637f72 to your computer and use it in GitHub Desktop.
Save clintar/af07d87f28b04e01183a8b8569637f72 to your computer and use it in GitHub Desktop.
# change this IP address to your miner's IP
$miner_ip="192.168.7.223"
$miner_status = Invoke-RestMethod -Uri "http://$miner_ip/status.json"
if(!$?)
{
Write-Output "Failed to connect to miner... exiting"
Exit 1
}
$snapshot_status = Invoke-RestMethod -Uri "https://us915.s3.amazonaws.com/assets/snaps/snapshot.json"
if(!$?)
{
Write-Output "Failed to check snapshot height"
Exit 1
}
$auth = 'bobcat' + ':' + 'miner'
$Encoded = [System.Text.Encoding]::UTF8.GetBytes($auth)
$authorizationInfo = [System.Convert]::ToBase64String($Encoded)
$headers = @{"Authorization"="Basic $($authorizationInfo)"}
$basicAuthValue = "Basic Ym9iY2F0Om1pbmVy"
$Headers = @{"Authorization"="Basic Ym9iY2F0Om1pbmVy"}
if ($response.miner_height -lt $snapshot_status.height)
{
Invoke-WebRequest -Uri "http://$miner_ip/admin/fastsync" -UseBasicParsing -Method POST -Headers $($Headers)
}
else
{
Write-Output "Miner is synced"
}
@clintar
Copy link
Author

clintar commented Oct 28, 2021

Click start menu, start typing powershell, open the Powershell ISE,
click the New Script icon in the top left,
paste contents of this gist into the document body,
change IP address at the top to your miner's local IP,
click save,
name it auto-check-miner-sync.ps1
This should save into the Documents folder by default. Take note of the path if you want to have this script run every so often.
then in the blue console area type
Documents\check-miner-sync.ps1
Check output to see if it worked

@clintar
Copy link
Author

clintar commented Oct 28, 2021

If you it tells you that scripts are not allowed to run, go to start menu, start typing powershell,
right-click on the powershell application name, and select run as administrator. when it comes up, type:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted and press enter
and then yes or yes to all

@clintar
Copy link
Author

clintar commented Oct 28, 2021

How to have it check continuously
click start menu icon,
start typing task,
click on task scheduler,
on right, click Create Basic Task,
name it something you will remember, click next,
on trigger page, select one time, click next,
keep start time as now, or set to some time in the past, click next,
on action select Start a program, click next
in Program/Script box type powershell, in Add arguments (optional) box, type -File <path-to-script.ps1> (something like C:\Users\clintar\Documetns\auto-check-miner-sync.ps1, click next
IMPORTANT, on the Finish page, select the checkbox for Open the Properties dialog for this task when I click Finish, then click Finish
When Properties dialog comes up, on General tab select Run whether user is logged in or not,
On Triggers tab, select the "One Time" area and click Edit. Set it to repeat something like every 30 minutes or whatever you want, click OK
On Settings tab, make sure Run task as soon as possible after a scheduled start is missed, then click OK at the bottom of this dialog,
enter your user's password

Optional to see keep a log of when it ran:
On the left hand side, click Task Scheduler Library.
You may have to right-click on Task Scheduler Library on the left to refresh the list, but select your task,
and on the right-hand side click on Enable All Task History
Doing this will let you see down below when selecting the History tab every time it ran so you know it's working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment