forked from damNmad/smartMiner
-
Notifications
You must be signed in to change notification settings - Fork 2
/
8wtm_auto_switch
208 lines (180 loc) · 8.66 KB
/
8wtm_auto_switch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
##########################################################################
##########################################################################
################# nvOC v0019-2.0 - Community Release #################
############## by papampi, Stubo and leenoox ##############
########## Based on the original nvOC v0019-1.4 by fullzero ##########
##########################################################################
##########################################################################
# WhatToMine.com Auto Switch by papampi
# for nvOC v0019-2.0 - Community Release
# DEV Mod Log:
#
# v=0001 : papampi: Initial Revision
#
# v=0002 : Papampi: Added 24 hour average revenue
#
# v=0003 : Papampi: Wait for miner start to prevent double miner running
#
# v=0004 : leenoox: Read curent coin from 1bash
#
# v=0005 : Papampi: Add Algo check to restart only miner or 3main
#
# v=0006 : Papampi: Check for last top coin whether its in coin list or not
#
# v=0007 : Papampi: Changes for plusCPU
#
# v=0008 : Papampi: Added minimum mining time, 24H Average revenue
#
# v=0009 : Papampi: Fixed minimum mining time
#
# v=0010 : Papampi: Yet another Fix for minimum mining time
#
# v=0011 : Papampi: Disable minimum mining time, causing problems
nvOC_Ver="nvOC v0019-2.0 - Community Release"
wtm_auto_switch_ver="v0019-2.0.0011" # Do not edit this
echo ""
echo ""
echo "WhatToMine.com Auto Switch $wtm_auto_switch_ver by papampi"
echo ""
source /home/m1/1bash
CURRENT_COIN=$COIN
WDOG_LOG="/home/m1/nvoc_logs/watchdog-screenlog.0"
# Creating a log file to record coin switch
LOG_FILE="/home/m1/nvoc_logs/8_wtmautoswitchlog"
if [[ -e "$LOG_FILE" ]] ; then
#Limit the logfile, just keep the last 5K
echo "$(cat $LOG_FILE | tail -n 5k)" > $LOG_FILE
fi
WTM_HISTORY="/home/m1/WTM_switch_history"
if [[ -e "$WTM_HISTORY" ]] ; then
#Limit the logfile, just keep the last 100 lines
echo "$(cat $WTM_HISTORY | tail -n 100)" > $WTM_HISTORY
fi
# Check last top coin and change if not in coin list any more
FIRST_COIN="$(echo $WTM_AUTO_SWITCH_COINS | awk -F'[_;]' '{print $1}')"
TOP_COIN=$(cat /home/m1/WTM_top_coin | sed 's/:[0-9]*//')
if [ -z $(echo $WTM_AUTO_SWITCH_COINS | grep $TOP_COIN) ]
then
echo "Last top coin not in current coin list any more, Switch to 1st coin"
sed -i "s/${TOP_COIN}/${FIRST_COIN}/g" /home/m1/WTM_top_coin
fi
while true
do
if [[ $AUTO_START_MINER == "YES" ]]; then
#Waiting for miner start before start switching
if [[ -z $(ps ax | grep SCREEN | grep miner | grep -v cpuminer) ]];then
echo "Miner not running" | tee -a $LOG_FILE
echo "" | tee -a $LOG_FILE
while [[ -z $(ps ax | grep SCREEN | grep miner | grep -v cpuminer) ]]; do
echo "Miner still not running, waiting ..." | tee -a $LOG_FILE
echo "" | tee -a $LOG_FILE
sleep 5
done
if [[ -n $(ps ax | grep SCREEN | grep miner | grep -v cpuminer) ]]; then
echo "Miner is running" | tee -a $LOG_FILE
#If miner running time is lower than given time don't check for better coin
#MINER_TIME=$(ps -eo pid,etimes | grep $(ps -ef | grep SCREEN | grep miner | grep -v cpuminer | head -1 | awk '{print $2}') | awk '{print $2}')
#MINER_TIME_MIN=$(( $MINER_TIME / 60 ))
#if [[ $MINER_TIME_MIN -lt $WTM_MINIMUM_MINING_TIME ]] ; then
#echo "Mining $CURRENT_COIN for $MINER_TIME_MIN minutes , looking for a better coin to mine in less than $(($WTM_MINIMUM_MINING_TIME - $MINER_TIME_MIN)) minutes" | tee -a $LOG_FILE
#sleep $(( (($WTM_MINIMUM_MINING_TIME - $MINER_TIME_MIN)) * 60 ))
#echo "Looking for better coin" | tee -a $LOG_FILE
#else
#echo "Mining $CURRENT_COIN for $MINER_TIME_MIN minutes, looking for a better coin to mine" | tee -a $LOG_FILE
fi
fi
python2.7 '/home/m1/WTM_SWITCHER' /home/m1/WTM.json | tee -a $LOG_FILE
sleep 5
source /home/m1/1bash # source 1bash again in case it was edited between our timer checks
CURRENT_COIN=$COIN
CURRENT_COIN_ALGORITHM=$ALGORITHM
TOP_COIN=$(cat /home/m1/WTM_top_coin | sed 's/:[0-9]*//')
TIMEIN=$WTM_AUTO_SWITCH_SYNC_INTERVAL
TIMEOUT=$(($TIMEIN * 60))
if [ $ALGO_SPECIFIC_OC == "YES" ]; then
if [ $TOP_COIN == "FTC" -o $TOP_COIN == "ORB" -o $TOP_COIN == "PXC" -o $TOP_COIN == "VIVO" -o $TOP_COIN == "TZC" ]; then
TOP_COIN_ALGORITHM="NEOSCRYPT"
fi
if [ $TOP_COIN == "ETH" -o $TOP_COIN == "ETC" -o $TOP_COIN == "EXP" -o $TOP_COIN == "UBQ" -o $TOP_COIN == "MUSIC" -o $TOP_COIN == "SOIL" -o $TOP_COIN == "PIRL" ]; then
TOP_COIN_ALGORITHM="ETHASH"
fi
if [ $TOP_COIN == "BTG" -o $TOP_COIN == "ZEC" -o $TOP_COIN == "ZEN" -o $TOP_COIN == "HUSH" -o $TOP_COIN == "ZCL" -o $TOP_COIN == "KMD" -o $TOP_COIN == "VOTE" ]; then
TOP_COIN_ALGORITHM="EQUIHASH"
fi
if [ $TOP_COIN == "SIGT" -o $TOP_COIN == "ALTCOM" ]; then
TOP_COIN_ALGORITHM="SKUNK"
fi
if [ $TOP_COIN == "XMR" -o $TOP_COIN == "KRB" -o $TOP_COIN == "ETN" ]; then
TOP_COIN_ALGORITHM="CRYPTONIGHT"
fi
if [ $TOP_COIN == "MONA" -o $TOP_COIN == "VTC" ]; then
TOP_COIN_ALGORITHM="LYRA2REV2"
fi
if [ $TOP_COIN == "ZCOIN" ]; then
TOP_COIN_ALGORITHM="LYRA2V2"
fi
fi
if [[ "$CURRENT_COIN" != "$TOP_COIN" ]]; then
sed -i '/^#/!s/'COIN=\"$CURRENT_COIN\"'/'COIN=\"$TOP_COIN\"/'' /home/m1/1bash
cat /home/m1/WTM_current_revenue | grep `cat /home/m1/WTM_top_coin | awk -F: '{print $1}'` | awk -F: '{print $2}' >> /home/m1/WTM_24H_REV
SYNC_COUNT=$((`expr 1440 / $WTM_AUTO_SWITCH_SYNC_INTERVAL`))
echo "$(tail -$SYNC_COUNT WTM_24H_REV)" > /home/m1/WTM_24H_REV
sed -i '/^$/d' /home/m1/WTM_24H_REV
sleep 1
echo "Current Coin Algo: $CURRENT_COIN_ALGORITHM" | tee -a $LOG_FILE
echo "Current Coin: $CURRENT_COIN" | tee -a $LOG_FILE
echo "Top Coin Algo: $TOP_COIN_ALGORITHM" | tee -a $LOG_FILE
echo "Top Coin: $TOP_COIN" | tee -a $LOG_FILE
if [[ $ALGO_SPECIFIC_OC == "NO" && $plusCPU == "NO" ]] || [[ $ALGO_SPECIFIC_OC == "YES" && $CURRENT_COIN_ALGORITHM == $TOP_COIN_ALGORITHM ]]; then
echo "Switching Coin with same Algo or ALGO_SPECIFIC_OC=No, Restarting miner" | tee -a $LOG_FILE
echo "" | tee -a $LOG_FILE
if [[ -n $(ps ax | grep -i screen | grep miner) ]]; then
echo "Miner is running, lets make the switch" | tee -a $LOG_FILE
if [[ $MINER_WATCHDOG == "YES" ]]; then
pkill -f 5watchdog
echo "WTM Auto Switch Restarted watchdog" | tee -a $LOG_FILE $WDOG_LOG
sleep 1
screen -c /home/m1/screenrc-watchdog -dmSL wdog bash /home/m1/5watchdog
echo "watchdog restarted in screen wdog; ~/nvOC wdog-log" | tee -a $LOG_FILE
echo "" | tee -a $LOG_FILE
fi
target=$(ps ax | grep -v cpuminer | grep -i screen | grep miner | awk '"miner" {print $1}')
kill $target
sleep 1
echo "Commencing Miner Start Command..." | tee -a $LOG_FILE
bash /home/m1/0miner
echo $( ps ax | grep miner | grep -o 'SCREEN.*' ) | tee -a $LOG_FILE
echo "process in screen miner; ~/nvOC miner-log" | tee -a $LOG_FILE
echo "" | tee -a $LOG_FILE
fi
elif [[ $ALGO_SPECIFIC_OC == "YES" && $CURRENT_COIN_ALGORITHM != $TOP_COIN_ALGORITHM ]]; then
echo "Switching Coin with ALGO_SPECIFIC_OC=YES and different Algo, Restarting 3main" | tee -a $LOG_FILE
pkill -f 5watchdog
echo "WTM Auto Switch Restarted watchdog" | tee -a $LOG_FILE $WDOG_LOG
sleep 1
pkill -f 3main
fi
echo "$(date) - Mining switched from $CURRENT_COIN to $TOP_COIN" | tee -a $LOG_FILE $WTM_HISTORY
echo "24 Hour Average Revenue: $(awk '{s+=$1}END{print "",s/NR}' RS="\n" /home/m1/WTM_24H_REV) $WTM_CURRENCY"
echo "Check again in $TIMEOUT seconds" | tee -a $LOG_FILE
echo "" | tee -a $LOG_FILE
echo "" | tee -a $LOG_FILE
sleep $TIMEOUT
else
echo "$(date) - Same Coin on Top, Continue mining $CURRENT_COIN" | tee -a $LOG_FILE
echo "24 Hour Average Revenue: $(awk '{s+=$1}END{print "",s/NR}' RS="\n" /home/m1/WTM_24H_REV) $WTM_CURRENCY"
echo "Check again in $TIMEOUT seconds" | tee -a $LOG_FILE
echo "" | tee -a $LOG_FILE
echo "" | tee -a $LOG_FILE
sleep 1
cat /home/m1/WTM_current_revenue | grep `cat /home/m1/WTM_top_coin | awk -F: '{print $1}'` | awk -F: '{print $2}' >> /home/m1/WTM_24H_REV
SYNC_COUNT=$((`expr 1440 / $WTM_AUTO_SWITCH_SYNC_INTERVAL`))
echo "$(tail -$SYNC_COUNT WTM_24H_REV)" > /home/m1/WTM_24H_REV
sed -i '/^$/d' /home/m1/WTM_24H_REV
sleep $TIMEOUT
fi
else
echo "Auto start miner set to NO" | tee -a $LOG_FILE
fi
done