Author

Topic: How: Ethos check hasrate reboot script (Read 299 times)

newbie
Activity: 6
Merit: 0
July 21, 2017, 09:53:14 AM
#1
So i saw this script on github.com, but i could not get it started maybe someone els using this script?
Im using EthOS, Claymoreminer

Code:
import subprocess
import os
import re
import sys
import argparse
import httplib, urllib

def pushover_message(title, message, app_token, user_token):
conn = httplib.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
  urllib.urlencode({
    "token": app_token,                       # Insert app token here
    "user": user_token,                       # Insert user token here
    "title": title,                  # Title of the message
    "message": message            # Content of the message
  }), { "Content-type": "application/x-www-form-urlencoded" })
return conn.getresponse()

parser = argparse.ArgumentParser()

parser.add_argument(
'-f',
'--checkfilepath',
dest='check_file_path',
help="path to store temporary file at if reboot criteria is met, but we need to wait until next time this script runs, check if that file exists, criteria are till met and then reboot",
default="/tmp/reboot_conditions_met_last_time.txt"
)

parser.add_argument('-a', '--pushover_app_token', dest='pushover_app_token',  help="app token for pushover service for push notifications on reboot")

parser.add_argument('-u', '--pushover_user_token', dest='pushover_user_token',  help="user token for pushover service for push notifications on reboot")

args = parser.parse_args()

update_data = subprocess.check_output(['update'])

hash = None
miner_id = ''

for line in update_data.splitlines():
if 'hash:  ' in line:
hash_line = line
hash_list = re.findall(r'\d+\.\d+', hash_line)

if len(hash_list) > 0:
hash = float(hash_list[0])

elif 'hostname:   ' in line:
hostname_list = re.findall(r'\w+', line)
if len(hostname_list) > 1:
miner_id = hostname_list[1]


if not hash:
#criteria are met
#check if file exists, meaning that conditions were met last time
if os.path.isfile(args.check_file_path):
print 'file here'
os.remove(args.check_file_path)
if args.pushover_user_token and args.pushover_app_token:
pushover_message(
'Miner {} restarted'.format(miner_id),
'Miner {} reached hash rate of 0'.format(miner_id),
args.pushover_app_token,
args.pushover_user_token
)
os.system("r")
else:
# create a file so that next time we know if has been at state for a while
os.system('touch {}'.format(args.check_file_path))
else:
# if the checkfile exists, remove it because the conditions are no longer met
if os.path.isfile(args.check_file_path):
os.remove(args.check_file_path)
Jump to: