forked from papampi/nvOC_by_fullzero_Community_Release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelegram
2117 lines (1581 loc) · 94.6 KB
/
telegram
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Telegram Info Script
# By BaliMiner et al...
# for nvOC by fullzero
# ref: http://bernaerts.dyndns.org/linux/75-debian/351-debian-send-telegram-notification
# v0019-2
source /home/m1/1bash
if [ $TELEGRAM_TYPE == "BaliMiner" ]
then
CHATID=$TELEGRAM_CHATID
APIKEY=$TELEGRAM_APIKEY
CURRENTHASH=`/usr/bin/curl -s http://localhost:3333 | sed '/Total/!d; /Speed/!d;' | awk '{print $6}' | awk 'NR == 3'`
GPU_UTILIZATIONS=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits)
TEMP=$(/usr/bin/nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader)
PD=$(/usr/bin/nvidia-smi --query-gpu=power.draw --format=csv,noheader)
FAN=$(/usr/bin/nvidia-smi --query-gpu=fan.speed --format=csv,noheader)
LF=$'\n'
PROFIT=$(cat /home/m1/current-profit)
MSG="$WORKERNAME $LF Current Hashrate: $CURRENTHASH $LF GPU_UTILIZATIONS: $GPU_UTILIZATIONS $LF TEMPS: $TEMP $LF POWERDRAW: $PD"
/usr/bin/curl -s -X POST --output /dev/null https://api.telegram.org/bot${APIKEY}/sendMessage -d "text=${MSG}" -d chat_id=${CHATID}
fi
#mod by damNmad
if [ $TELEGRAM_TYPE == "damNmad" ]
then
CHATID=$TELEGRAM_CHATID
APIKEY=$TELEGRAM_APIKEY
SYSTEM_BOOT_TIME=$(uptime -s)
SYSTEM_UP_TIME=$(uptime -p)
GPU_COUNT=$(nvidia-smi -L | tail -n 1| cut -c 5 |awk '{ SUM += $1+1} ; { print SUM }')
MINER_UP_TIME=$(ps -p `pgrep miner` -o etime | grep -v ELAPSED)
CURRENTLY_MINING=$(ps aux | grep miner)
GPU_UTILIZATIONS=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits)
TEMP=$(/usr/bin/nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader)
PD=$(/usr/bin/nvidia-smi --query-gpu=power.draw --format=csv,noheader)
FAN=$(/usr/bin/nvidia-smi --query-gpu=fan.speed --format=csv,noheader)
CURRENTHASH=`/usr/bin/curl -s http://localhost:3333 | sed '/Total/!d; /Speed/!d;' | awk '{print $6}' | awk 'NR == 3'`
LF=$'\n'
PROFIT=$(cat /home/m1/current-profit)
MSG=" Worker: $WORKERNAME
Current Hashrate: $CURRENTHASH
System Boot Time: $SYSTEM_BOOT_TIME
System Up Time: $SYSTEM_UP_TIME
Miner Uptime: $MINER_UP_TIME
GPU Count: $GPU_COUNT
$LF GPU_UTILIZATIONS: $GPU_UTILIZATIONS
$LF TEMPS: $TEMP
$LF POWERDRAW: $PD
$LF FAN SPEEDS: $FAN
$LF $CURRENTLY_MINING"
/usr/bin/curl -m 5 -s -X POST --output /dev/null https://api.telegram.org/bot${APIKEY}/sendMessage -d "text=${MSG}" -d chat_id=${CHATID}
fi
#mod by papampi
if [ $TELEGRAM_TYPE == "papampi" ]
then
CHATID=$TELEGRAM_CHATID
APIKEY=$TELEGRAM_APIKEY
touch /home/m1/nvoc_logs/tempcontrol-screenlog.0
source /home/m1/1bash
SYSTEM_BOOT_TIME=$(uptime -s)
SYSTEM_UP_TIME=$(uptime -p)
GPU_COUNT=$(nvidia-smi -i 0 --query-gpu=count --format=csv,noheader,nounits)
REBOOT_REQUIRED=$([ -f /var/run/reboot-required ] && echo "Yes!!!" || echo "No")
GPU_UTILIZATIONS=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits | tr '\n' ' ')
TEMP_FAN_POWER=$(tail -n 50 /home/m1/nvoc_logs/tempcontrol-screenlog.0 | grep GPU | awk '{gsub(/:/,": ")}1' |tail -n $GPU_COUNT | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g')
WDOG_WARNINGS=$(tail -10 /home/m1/5_watchdoglog )
TEMP_WARNINGS=$(tail -10 /home/m1/6_autotemplog )
if [[ -n $(ps ax | grep SCREEN | grep miner | awk '"miner" {print $1}') ]]
then
MINER_PID=$(ps ax | grep SCREEN | grep miner | awk '"miner" {print $1}')
MINER_UP_TIME=$(ps -p $MINER_PID -o etime | grep -v ELAPSED)
else
MINER_UP_TIME=("Not Running")
fi
########### Auto Switch History and current mining ##############
if [ $COIN == "SALFTER_MPH_PROFIT_SWITCHING" ]
then
CURRENT_COIN=$(head -n 1 /home/m1/current-profit)
MINING_HISTORY=$(tail -n 5 /home/m1/algo_log | awk '{print $0}')
AUTO_SWITCH=("Salfter MPH Auto Switch")
elif [ $COIN == "SALFTER_NICEHASH_PROFIT_SWITCHING" ]
then
CURRENT_COIN=$(head -n 1 /home/m1/current-profit)
MINING_HISTORY=$(tail -n 5 /home/m1/algo_log | awk '{print $0}')
AUTO_SWITCH=("Salfter Nicehash Auto Switch")
elif [ $WTM_AUTO_SWITCH == "YES" ]
then
CURRENT_COIN="Mining Coin: $COIN"
MINING_HISTORY="Mining History: $LF$(cat /home/m1/WTM_switch_history | grep 'Mining switched'|tail -n 5 | awk '{print $0}')"
WTM_PROFIT="WTM Current Profit: $(cat /home/m1/WTM_current_profit | awk '{print $0,"%"}')"
WTM_REV="WTM Current Revenue ($WTM_CURRENCY): $(cat /home/m1/WTM_current_revenue | awk '{print $0,""}')"
WTM_AVERAGE_REV="24H Average Revenue: $(awk '{s+=$1}END{print "",s/NR}' RS="\n" /home/m1/WTM_24H_REV)"
BTC_PRICE="BTC Price: $(cat /home/m1/WTM_BTC_EXCHANGE_RATE | awk '{printf("%d\n",$1 + 0)}' )"
if ps aux | grep -v grep | grep -q 8wtm_auto_switch
then
WTM_SWITCH=("Running")
else
WTM_SWITCH=("Not Running")
fi
AUTO_SWITCH=("WTM Auto Switch $WTM_SWITCH $WTM_A_S")
elif [ $WTM_PROFIT_CHECK == "YES" ] && [ $WTM_AUTO_SWITCH == "NO" ]
then
CURRENT_COIN="Mining Coin: $COIN"
MINING_HISTORY=""
WTM_PROFIT="WTM Current Profit: $(cat /home/m1/WTM_current_profit | awk '{print $0,"%"}')"
WTM_REV=$(cat /home/m1/WTM_current_revenue | awk '{print $0,""}')
WTM_SWITCH=("WTM Profit Check Running. ")
BTC_PRICE="BTC Price: $(cat /home/m1/WTM_BTC_EXCHANGE_RATE | awk '{printf("%d\n",$1 + 0)}' )"
WTM_AVERAGE_REV=""
AUTO_SWITCH=""
else
CURRENT_COIN="Mining Coin: $COIN"
AUTO_SWITCH="No Auto Switch"
MINING_HISTORY=""
BTC_PRICE=""
WTM_PROFIT=""
WTM_REV=""
WTM_AVERAGE_REV=""
fi
LF=$'\n'
MSG=" Worker: $WORKERNAME $LF Boot Time: $SYSTEM_BOOT_TIME $LF System Up Time: $SYSTEM_UP_TIME $LF Miner Uptime: $MINER_UP_TIME $LF $CURRENT_COIN $LF $BTC_PRICE $LF Reboot Required: $REBOOT_REQUIRED $LF GPU Count: $GPU_COUNT $LF GPU Utilization: $LF $GPU_UTILIZATIONS $LF Temp, Fan, Power: $LF $TEMP_FAN_POWER $LF $LF Auto Switch: $LF$AUTO_SWITCH $LF $LF $MINING_HISTORY $LF $LF$WTM_PROFIT $LF $LF $WTM_REV $LF $LF $WTM_AVERAGE_REV $WTM_CURRENCY $LF $WDOG_WARNINGS $LF $TEMP_WARNINGS"
/usr/bin/curl -m 5 -s -X POST --output /dev/null https://api.telegram.org/bot${APIKEY}/sendMessage -d "text=${MSG}" -d chat_id=${CHATID}
fi
#mod by kk003
if [ $TELEGRAM_TYPE == "kk003" ]
then
#!/bin/bash
# Telegram Info/Alerts Script
# for nvOC by fullzero
# mod by kk003 ;-)
# Script name: kk003_telegram
# Version: 1.1
# You must create a bot and get your new user/chat Id + Api key.
# Tutorials:
# Tutorial how to create a telegram bot: http://bernaerts.dyndns.org/linux/75-debian/351-debian-send-telegram-notification
# Video tutorial how to create a telegram bot by kk003: https://youtu.be/HS7Q1zH00bs
# Enlace hilo foro para OP+video+instalar en nvoc 19 estable
#####
# if you fancy the script you can make a donation. Will be greatly appreciated
# BTC: 0x196pMZnByg5UaPvJPK67ErAHgDPeSyu8QV
# ETH: 0x628dD8d1264543292C68F4C587012BaCe805891A
# ETC: 0x60d3349263a313e86DFCFA090FB12169A786D0E9
# EXP: 0xF590cE35961D0B22aFEd57cc35FDE96E8802d0bC
# MUSIC: 0x40b44982642acf21b7bde576a9f555cad94f6b9b
# ZEC: 0xt1UuA5MKU18kJKMEyuQaVpdNtm552kHkDo3
#####
#
## Keep this block of code at the begining of script or it will complain about name of the log file
#
# Log file location
KK003_LOG_FILE=~/kk003_telegram_data/kk003_telegram.log
# I need to have some data over restarts like ips. I'll use a file to do so
DATA_FILE=~/kk003_telegram_data/data
# Create the working dirs so I keep things tidy
if [[ ! -d ~/kk003_telegram_data ]]; then
mkdir ~/kk003_telegram_data
fi
if [[ ! -d ~/kk003_telegram_data/files ]]; then
mkdir ~/kk003_telegram_data/files
fi
# Create the log file
if [[ ! -f "$KK003_LOG_FILE" ]]; then
touch $KK003_LOG_FILE
fi
# Create the file to hold some data I'll need over restarts.
if [[ ! -f $DATA_FILE ]]; then
touch $DATA_FILE
fi
START_TIME=`date "+%Y-%m-%d %H:%M:%S"`
#
## End of block of code at the begining of script
#####
( ##### DON'T REMOVE THIS OPEN PARENTHESIS OR WE'LL MISS THE LOG FILE
### Some vars related to telegram and sending alerts you may want to customize
#
TELEGRAM_CURRENT_CHARS_LIMT=4096 # Telegram gives a "400 BAD_REQUEST MESSAGE_TOO_LONG" if length >= 4096 UTF8 characters
# so I will check the length before send msg
USE_NVOC_DEFAULT_TIMES_TELEGRAM=0 # 0, send a telegram when this script thinks is right (warnings) or when its time to do so as var "USER_CUSTOM_TIMES_TO_SEND_TELEGRAM" says
# 1, send a telegram's NVOC style, that is at the interval var "TELEGRAM_TIMEOUT_IN_MINUTES" in 1bash says, no matter a problem is detected or not
ON_WARNING_NUMBER_TELEGRAMS_TO_SEND=3 # Max number of telegrams to send per warning (NO all warning listen to this var!!)
# Warnings auto-clear when resolved or when system/Xorg is restarted but not all warning are counted here
# You may get more telegrams than the value used here if there's more
# than one warning active at the same time as warnings are independent from each other
SYNC_TELEGRAM_SYSTEM=1 # 0, DON'T sync telegram system when value in var TELEGRAM_TIMEOUT_IN_MINUTES in 1bash is changed by user
# 1, SYNC telegram system when value in var TELEGRAM_TIMEOUT_IN_MINUTES in 1bash is changed by user
USE_USER_CUSTOM_TIMES_TELEGRAM=1 # 0, ignore user custom times to send telegram (in var "USER_CUSTOM_TIMES_TO_SEND_TELEGRAM")
# 1, use user custom times to send telegram (allows you to send telegrams at the times of day you want , or almost ;-))
# Send msg at certain hours of the day (I have been warned not to use cron so I do this job in the script)
# For this array to work you MUST use the following format:
# 1. 00-23 for hours (notice two digits)
# 2. 00-59 for minutes (notice two digits)
# 3. ":" between hours and minutes
# 4. Values between quotation marks
# 5. Values must be space separated
# Example: USER_CUSTOM_TIMES_TO_SEND_TELEGRAM=("11:00" "16:00" "20:00" )
#
# You'll get a telegram if you use a wrong format!!!
# REMENBER: 00:00 won't work. You won't get a telegram at this time (may be i'll fix it later some time)
# REMENBER: first time of day is 00:01 and last is 23:59
# REMENBER: You'll never get a telegram at 00:00, set it up to 00:01 (yes, again)
# REMENBER: If times you ask here for a telegram are in intervals smaller than value of var "TELEGRAM_TIMEOUT_IN_MINUTES" in /home/m1/1bash
# you'll only get one of them (usually the one closest to time 00:01 of that day)
# When this script is running it checks if time left to send a telegram is less than time left for next check. If so "sleeps" until it's time to send the msg
# So, you better set up var "TELEGRAM_TIMEOUT_IN_MINUTES" in /home/m1/1bash at 10, 15, 20, or 30 minutes max. That way you'll get a rich log file full of info
#
#
USER_CUSTOM_TIMES_TO_SEND_TELEGRAM=("12:00" "18:00" "21:32")
# The script supports multi-telegrams. That is it can send the telegram message to several recipients
# In /home/m1/1bash, as allways you still have to add your USER ID to variable "TELEGRAM_CHATID" and your API KEY to varible "TELEGRAM_APIKEY"
# Then add the additional chats that you want to send a telegram to this variable
# Data must be added this way:
# 1. 2 values for chat
# 2. First value is the API KEY
# 3. Second value is the User ID / Channel ID - The first if you send the telegram to a user, the second if you send tehe telegram to a channel
# but the field is the same one for any of them and it has to be only one here
# Example for two additional:
# TELEGRAM_ADDITIONAL_RECIPIENTS=(
# "455957604:AAHBEMidb2894YUBZq5dXRSL9lFbgHvE808"
# "12345678"
# "456545604:4rttyMidb283456yhg5dXRSL9lFbgHv6yhj"
# "12309898"
# )
TELEGRAM_ADDITIONAL_RECIPIENTS=(
)
# The warnings file holds how many times a warning has occurred for a registered element
#
WARNINGS_FILE=~/kk003_telegram_data/kk003_warnings # The warnings file
#### Some values you may want to customize for "function my_custom_mods_for_nvidia_smi"
#
CENTIGRADO="ºC" # Symbol you want after the gpu temp value
# Aliases:
MODELS=("GeForce GTX 1060 3GB" "GF1060_3G" "GeForce GTX 1060 6GB" "GF1060_6G" "GeForce GTX 970" "GF970_4G") # Cos telegram cut off the lines I want to make
# them as short as possible.
# Just add the gpu name such as is showen by nvidia-smi
# follow by the alias you want
# Fields must be space separated and in quotation marks
# I recommend not to use spaces in aliases
USE_GPU_ALIAS="YES" # "YES or "NO" If yes replaces the gpu's name with the alias. See variable "MODELS"
#### Some values you may want to customize for "function my_custom_mods_for_nvidia_smi"
#
# Query arguments for "function my_custom_mods_for_nvidia_smi"
# You can get a complete list of the query arguments by issuing: nvidia-smi --help-query-gpu
# Add/remove what you want here. Args must be coma separated
NVIDIA_SMI_QUERY_ARGUMENTS="index,gpu_name,gpu_bus_id,pstate,utilization.gpu,power.draw,temperature.gpu,fan.speed,clocks.mem,clocks.gr,memory.used"
USE_function_my_custom_mods_for_nvidia_smi="YES" # YES or NO, say "YES" here to use my custom data arrange provided for this function
# say "NO" to get the standar data output from nvidia-smi
MODE_NVIDIA_SMI_REPORT=2 # 0 or 1 or 2 0 Don't use minimal output data but query arguments in var "NVIDIA_SMI_QUERY_ARGUMENTS"
# 1 Only minimal output is used and shown as a BLOCK. Overrides query arguments in var
# "NVIDIA_SMI_QUERY_ARGUMENTS" and "USE_function_my_custom_mods_for_nvidia_smi" too (see var above).
# 2 Only minimal output is used and shown as MODULES PER ARGUMENT. Overrides query arguments in var
# "NVIDIA_SMI_QUERY_ARGUMENTS" and "USE_function_my_custom_mods_for_nvidia_smi" too (see var above).
# Legend for headers on MODE_NVIDIA_SMI_REPORT=1 (function nvidia_smi_minimal_report)
# GID = gpu index
# GPN = gpu name
# GUT = utilization gpu
# GPL = power limit
# GPD = power draw
# GTP = temperature gpu
# GFS = fan speed
#### Some values you may want to customize for "function system_info" (I think most names are self explanatory)
#
# Some warning you can choose to get via telegram or not
SEND_WARNING_SYSTEM_RESTARTED="YES" # YES or NO
SEND_WARNING_XORG_RESTARTED="YES" # YES or NO
SEND_WARNING_LOAD_AVERAGE="YES" # YES or NO
SEND_WARNING_CHECK_DISPLAY="YES" # YES or NO
SEND_WARNING_WHEN_NO_L_ON_SCREEN="YES" # YES or NO YES send a telegram when screen is not starting miner with -L (create log file)
#
# some information you can choose to receive or not on your telegram msg
SEND_REBOOT_REQUIRED="YES" # YES or NO
SEND_WORKERNAME="YES" # YES or NO
SEND_MINING_COIN="YES" # YES or NO
SEND_MINING_ADDRESS="YES" # YES or NO
MASK_MINING_ADDRESS="YES" # YES or NO
SEND_MINER_EXEC_NAME="YES" # YES or NO
SEND_MINER_EXEC_PATH="YES" # YES or NO
SEND_MINER_UP_TIME="YES" # YES or NO
SEND_PRIVATE_IP="YES" # YES or NO
SEND_PUBLIC_IP="YES" # YES or NO
MASK_PUBLIC_IP="YES" # YES or NO
SEND_SSHD_PORT="YES" # YES or NO
SEND_UP_SINCE="YES" # YES or NO
SEND_UP_TIME="YES" # YES or NO
SEND_RAM="YES" # YES or NO
SEND_CPU_MODEL="YES" # YES or NO
SEND_LOGGED_USERS="YES" # YES or NO
CUSTOMIZE_SYSTEM_NAME="" # "PRIVATE_IP" or "PUBLIC_IP" or "AnY CusTom nAme you want here", if empty it uses the system's hostname
# This is the main header you'll get in your telegram message
# PRIVATE_IP will use your private ip/s (remenber you may have more than one)
# PUBLIC_IP will use your public ip
# This is a very important var you MUST customize!!!!
NUMBER_GPUS_FOR_SURE=5 # Number of gpus you know for sure your system must have
# Change this value to the number of gpus your system have or you will get a false warning
#### Some values you may want to customize for function claymore_statics"
#
USE_CLAYMORE_STATICS="YES" # YES or NO, if claymore is running use the provided data?
KEY_CLAYMORE="ethdcrminer64" # String I search for to check if claymore is running
# Different vesions may have different name.
# You must check if this entry is right for your
# system to get the script runnin correctly (OK for versions 8 to 10 at 2017/09/23 )
USE_GENOIL_STATICS="YES" # YES or NO, if Genoil is running use the provided data?
KEY_GENOIL=~/eth/Genoil-U/ethminer # String I search for to check if claymore is running
# Different vesions may have different name.
USE_ETHMINER_STATICS="YES" # YES or NO, if Ethminer is running use the provided data?
KEY_ETHMINER_1=~/eth/ethminer_11/ethminer # Strings I search for to check if claymore is running
KEY_ETHMINER_2=~/eth/ethminer_12dev2/ethminer # Different vesions may have different name.
# Error exit codes (or RETURN VALUE as nvidia call them) for nvidia-smi
# I'll treat them as an array so in couples; firt value is the code number and second value is the text that explains it
NVIDIA_SMI_RETURN_VALUE=(
"0" "Success"
"2" "A supplied argument or flag is invalid"
"3" "The requested operation is not available on target device"
"4" "The current user does not have permission to access this device or perform this operation"
"6" "A query to find an object was unsuccessful"
"8" "A device is external power cables are not properly attached"
"9" "NVIDIA driver is not loaded"
"10" "NVIDIA Kernel detected an interrupt issue with a GPU"
"12" "NVML Shared Library couldn't be found or loaded"
"13" "Local version of NVML doesn't implement this function"
"14" "infoROM is corrupted"
"15" "The GPU has fallen off the bus or has otherwise become inaccessible"
"255" "Other error or internal driver error occurred"
)
LF=$'\n' # New line
##
#
# Below here don't change value of vars/code unless you know what you are doing
#
##
# Functions
#
function nvidia_smi_minimal_report ()
{
# Empty the files
> ~/kk003_telegram_data/files/nvidia_smi_values.csv
> ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
if [[ $MODE_NVIDIA_SMI_REPORT -eq 1 ]]; then
# Query the values I want
nvidia-smi --query-gpu=index,gpu_name,utilization.gpu,power.limit,power.draw,temperature.gpu,fan.speed --format=csv,noheader > ~/kk003_telegram_data/files/nvidia_smi_values.csv
# Mount the header for mode 1
HEADER_MINIMAL_NVIDIA_SMI="GID GPN GUT GPL GPD GTP GFS"
# Lines in file should be same as gpus
LINES_TO_MODIFY=$GPU_COUNT
# Arrange the output for the "temperature.gpu" nvidia-smi argument
# I want to add "ºC"
#
# Column number for temperature.gpu in file
COLUMN_NUMBER_TEMPERATURE_GPU=6
for ((L=1; L <= $LINES_TO_MODIFY ; L=L+1))
do
OLD_VALUE=`sed -n -e "${L}p" ~/kk003_telegram_data/files/nvidia_smi_values.csv | cut -d, -f$COLUMN_NUMBER_TEMPERATURE_GPU` # Extraigo el dato original
NEW_VALUE=$OLD_VALUE$CENTIGRADO
sed -i "$L"'s/^\(\([^,]*,\)\{'"$(($COLUMN_NUMBER_TEMPERATURE_GPU -1))"'\}\)[^,]*/\1'"$NEW_VALUE"'/' ~/kk003_telegram_data/files/nvidia_smi_values.csv
done
# Copy the telegram file to the log file
cp ~/kk003_telegram_data/files/nvidia_smi_values.csv ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
# Call function to change gpu's name for alias (modify files for telegram and log file)
gpu_names_to_alias
# Try to align columns for log file (stupid for telegram but not for the log file)
cat ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv | column -s, -t > ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv.temp
# Set log file in place
cp ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv.temp ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
# Insert header in log file
sed -i "1s/^/$HEADER_MINIMAL_NVIDIA_SMI\n/" ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
# Change "," for " " in telegram file
sed -i 's/,/ /g' ~/kk003_telegram_data/files/nvidia_smi_values.csv
# Insert header in telegram file
sed -i "1s/^/$HEADER_MINIMAL_NVIDIA_SMI\n/" ~/kk003_telegram_data/files/nvidia_smi_values.csv
fi
if [[ $MODE_NVIDIA_SMI_REPORT -eq 2 ]]; then
# nvidia-smi --query-gpu=index,gpu_name,utilization.gpu,power.limit,power.draw,temperature.gpu,fan.speed --format=csv,noheader | sed 's/ //g' | sed 's/ /\n/g' > ~/kk003_telegram_data/files/nvidia_smi_values.csv
# utilization.gpu
echo "Gpu_Utilization:" >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
nvidia-smi --query-gpu=index,gpu_name,utilization.gpu --format=csv,noheader >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
echo >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
# power limt
echo "Gpu_power_limit:" >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
nvidia-smi --query-gpu=index,gpu_name,power.limit --format=csv,noheader >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
echo >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
# power draw
echo "Gpu_power_draw:" >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
nvidia-smi --query-gpu=index,gpu_name,power.draw --format=csv,noheader >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
echo >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
# gpu temperature
echo "Gpu_temperature_($CENTIGRADO):" >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
nvidia-smi --query-gpu=index,gpu_name,temperature.gpu --format=csv,noheader >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
echo >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
# gpu fan speed
echo "Gpu_fan_speed:" >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
nvidia-smi --query-gpu=index,gpu_name,fan.speed --format=csv,noheader >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
echo >> ~/kk003_telegram_data/files/nvidia_smi_values.csv
# Set log file in place
cp ~/kk003_telegram_data/files/nvidia_smi_values.csv ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
# Call function to change gpu's name for alias (modify files for telegram and log file)
gpu_names_to_alias
# Replace " " for nothing and "," for spaces
sed -i 's/ //g; s/,/ /g;' ~/kk003_telegram_data/files/nvidia_smi_values.csv
sed -i 's/ //g; s/,/ /g;' ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
# Try to align columns for log file (stupid for telegram but not for the log file)
cat ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv | column -t > ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv.temp
# Set log file in place
cp ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv.temp ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
fi
}
function gpu_names_to_alias ()
{
##### Changing the gpu's name for the alias (if I have it)
#
if [[ "$USE_GPU_ALIAS" == "YES" ]]; then
# First must check that elements in the array are a even number and is not empty
MODELS_LENGTH=${#MODELS[@]} # Get number of elements
if [[ $MODELS_LENGTH -ne 0 ]]; then # Is not empty
if [[ $((MODELS_LENGTH%2)) -eq 0 ]]; then # Number of elements is even?. If so I assume names and alias are well matched in array
for ((INDEX_EVEN=0; INDEX_EVEN < $MODELS_LENGTH ; INDEX_EVEN=INDEX_EVEN+2)) # First element of array have index 0
do # Even elements are the gpu names, odd elements are alias
NAME_GPU_IN_ARRAY=${MODELS[$INDEX_EVEN]} # Get the name of the gpu in array
INDEX_ODD=$(($INDEX_EVEN + 1)) # +1 to get the alias index
ALIAS_GPU_IN_ARRAY=${MODELS[$INDEX_ODD]} # Get the alias of the gpu in array
# Find and replace gpu name if exists
sed -i "s/${NAME_GPU_IN_ARRAY}/${ALIAS_GPU_IN_ARRAY}/g" ~/kk003_telegram_data/files/nvidia_smi_values.csv
sed -i "s/${NAME_GPU_IN_ARRAY}/${ALIAS_GPU_IN_ARRAY}/g" ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
done
# I get this way out if number of elements in array are odd and I don't replace names for alias
else
echo "Number of elements in variable MODELS are odd and I don't replace gpu names for alias."
echo "Check variable MODELS if you want to replace names for alias"
fi
# I get this way out if array in variable MODELS is empty
else
echo "Variable MODELS is empty and I don't replace gpu names for alias."
echo "Check variable MODELS if you want to replace names for alias"
fi
fi
##### END of Changing gpu's name by the alias (if I have it)
}
function my_custom_mods_for_nvidia_smi ()
{
# I organize some things my way
# comment out the call to this function and you will get the standar output from nvidia-smi
###
# Beginning of block
###
# Save header and remove it from the csv file
CSV_HEADER=$(cat ~/kk003_telegram_data/files/nvidia_smi_values.csv | head -n 1 | sed 's/ //g' | sed 's/,/ /g') # Save the header of csv file
sed -i -e "1d" ~/kk003_telegram_data/files/nvidia_smi_values.csv # Remove the header of telegram file (first line)
sed -i -e "1d" ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv # Remove the header of log file (first line)
# Call function to change gpu's name for alias
gpu_names_to_alias
# I don't want any spaces but to align thing
sed -i 's/ //g' ~/kk003_telegram_data/files/nvidia_smi_values.csv
sed -i 's/ //g' ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
# Get number of elements on NVIDIA_SMI_QUERY_ARGUMENTS variable
NVIDIA_SMI_QUERY_ARGUMENTS_LENGTH=$(echo $NVIDIA_SMI_QUERY_ARGUMENTS | sed 's/[^,]//g' | wc -c)
# Review all elements in variable NVIDIA_SMI_QUERY_ARGUMENTS and do some mods about the output for some fields
for ((INDEX=1; INDEX <= $NVIDIA_SMI_QUERY_ARGUMENTS_LENGTH ; INDEX=INDEX+1)) # Gives me the column number
do
NVIDIA_SMI_ARGUMENT=$(echo $NVIDIA_SMI_QUERY_ARGUMENTS | cut -d, -f $INDEX) # Gives me the name of nvidia-smi argument on array
#### Arrange the output for the "index" nvidia-smi argument
#### I want to aling numbers <= 9 if I have more than 9 gpus so I add a space in front
if [[ "$NVIDIA_SMI_ARGUMENT" == "index" && $GPU_COUNT -gt 10 ]]; then
LINES_TO_MODIFY=10
for ((L=1; L <= $LINES_TO_MODIFY ; L=L+1))
do
OLD_VALUE=`sed -n -e "${L}p" ~/kk003_telegram_data/files/nvidia_smi_values.csv | cut -d, -f$INDEX` # Extraigo el dato original
NEW_VALUE=" "$OLD_VALUE
sed -i "$L"'s/^\(\([^,]*,\)\{'"$(($INDEX -1))"'\}\)[^,]*/\1'"$NEW_VALUE"'/' ~/kk003_telegram_data/files/nvidia_smi_values.csv
sed -i "$L"'s/^\(\([^,]*,\)\{'"$(($INDEX -1))"'\}\)[^,]*/\1'"$NEW_VALUE"'/' ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
done
fi
#### END of Arrange the output for the "index" nvidia-smi argument
#### Arrange the output for the "pci.bus_id" nvidia-smi argument
#### I don't want the "00000000:" at the beginning
if [[ "$NVIDIA_SMI_ARGUMENT" == "gpu_bus_id" ]]; then
LINES_TO_MODIFY=$GPU_COUNT
for ((L=1; L <= $LINES_TO_MODIFY ; L=L+1))
do
OLD_VALUE=`sed -n -e "${L}p" ~/kk003_telegram_data/files/nvidia_smi_values.csv | cut -d, -f$INDEX` # Extraigo el dato original
NEW_VALUE=$(echo "$OLD_VALUE" | sed "s/00000000://")
sed -i "$L"'s/^\(\([^,]*,\)\{'"$(($INDEX -1))"'\}\)[^,]*/\1'"$NEW_VALUE"'/' ~/kk003_telegram_data/files/nvidia_smi_values.csv
sed -i "$L"'s/^\(\([^,]*,\)\{'"$(($INDEX -1))"'\}\)[^,]*/\1'"$NEW_VALUE"'/' ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
done
fi
#### END of Arrange the output for the "index" nvidia-smi argument
#### Arrange the output for the "utilization.gpu" nvidia-smi argument
#### I want to aling values to the right and keep the "%"
if [[ "$NVIDIA_SMI_ARGUMENT" == "utilization.gpu" ]]; then
LINES_TO_MODIFY=$GPU_COUNT
for ((L=1; L <= $LINES_TO_MODIFY ; L=L+1))
do
OLD_VALUE=`sed -n -e "${L}p" ~/kk003_telegram_data/files/nvidia_smi_values.csv | cut -d, -f$INDEX` # Extraigo el dato original
LEN=${#OLD_VALUE}
case $LEN in
2) NEW_VALUE=" "$OLD_VALUE
;;
3) NEW_VALUE=" "$OLD_VALUE
;;
*) NEW_VALUE=$OLD_VALUE
;;
esac
sed -i "$L"'s/^\(\([^,]*,\)\{'"$(($INDEX -1))"'\}\)[^,]*/\1'"$NEW_VALUE"'/' ~/kk003_telegram_data/files/nvidia_smi_values.csv
sed -i "$L"'s/^\(\([^,]*,\)\{'"$(($INDEX -1))"'\}\)[^,]*/\1'"$NEW_VALUE"'/' ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
done
fi
#### END of Arrange the output for the "utilization.gpu" nvidia-smi argument
#### Arrange the output for the "temperature.gpu" nvidia-smi argument
#### I want to aling values to the right and add the "ºC"
if [[ "$NVIDIA_SMI_ARGUMENT" == "temperature.gpu" ]]; then
LINES_TO_MODIFY=$GPU_COUNT
for ((L=1; L <= $LINES_TO_MODIFY ; L=L+1))
do
OLD_VALUE=`sed -n -e "${L}p" ~/kk003_telegram_data/files/nvidia_smi_values.csv | cut -d, -f$INDEX` # Extraigo el dato original
LEN=${#OLD_VALUE}
case $LEN in
1) NEW_VALUE=" "$OLD_VALUE$CENTIGRADO
;;
2) NEW_VALUE=" "$OLD_VALUE$CENTIGRADO
;;
*) NEW_VALUE=$OLD_VALUE$CENTIGRADO
;;
esac
sed -i "$L"'s/^\(\([^,]*,\)\{'"$(($INDEX -1))"'\}\)[^,]*/\1'"$NEW_VALUE"'/' ~/kk003_telegram_data/files/nvidia_smi_values.csv
sed -i "$L"'s/^\(\([^,]*,\)\{'"$(($INDEX -1))"'\}\)[^,]*/\1'"$NEW_VALUE"'/' ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
done
fi
#### END of Arrange the output for the "temperature.gpu" nvidia-smi argument
done
# Insert the whole header line as the first one
sed -i "1s/^/$CSV_HEADER\n/" ~/kk003_telegram_data/files/nvidia_smi_values.csv
sed -i "1s/^/$CSV_HEADER\n/" ~/kk003_telegram_data/files/nvidia_smi_values_log_file.csv
###
# End of block with custom my mods
###
}
function genoil_statics ()
{
#### Arrange the output for Genoil statics
if [[ "$ETHMINER_or_GENOIL_or_CLAYMORE" == "GENOIL" ]]; then
# Check if Genoil is really running. Note that I have to search the full path as there is a few miners with the same exec's name
ps aux | grep -v grep | grep miner | grep -q "$KEY_GENOIL"
if [[ $? -eq 0 ]]; then
GENOIL_IS_RUNNING="YES"
KNOWN_MINER_RUNNING=1 # 1= I known this miner
GENOIL_NUMBER_OF_HASHRATES_TO_SHOW=3 # Default 3, and I want to keep this value independent for each miner
echo ""
echo "It seems that GENOIL is running!!"
# Clear the files
> ~/kk003_telegram_data/files/miner_statics.txt
> ~/kk003_telegram_data/files/miner_statics_log_file.txt
# Insert Genoil's header
echo "" >> ~/kk003_telegram_data/files/miner_statics.txt
echo "-- Genoil mining Information :" >> ~/kk003_telegram_data/files/miner_statics.txt
echo "" >> ~/kk003_telegram_data/files/miner_statics_log_file.txt
echo "-- Genoil mining Information :" >> ~/kk003_telegram_data/files/miner_statics_log_file.txt
# Extract the output from screen ---> I have tested this method all night long and it is UNSTABLE. At any given moment it stops writing the file.
# > ~/kk003_telegram_data/files/output_miner_from_screen
# TIMEOUT_FOR_TIMEOUT_IN_SECONDS=20 # The timeout for the command timeout to wait
# echo "Running timeout+script+screen for $TIMEOUT_FOR_TIMEOUT_IN_SECONDS seconds"
# timeout $TIMEOUT_FOR_TIMEOUT_IN_SECONDS script -q ~/kk003_telegram_data/files/output_miner_from_screen --command "screen -dr miner"
# sleep 2
# screen -d miner # does not seem to need to be Detached
# Check if user is currently using option -L with screen when he started the miner and get statics from screenlog.o file
if [[ -f ~/screenlog.0 ]]; then
SLEEP_TIME_MODIFICATION_FILE=10 # Hope 10 segs is enough for screen to write new data and save the file
# Get date now in seconds
TIME_SCREEN_LOG_FILE_NOW_IN_SECONDS=$(stat -c %Y ~/screenlog.0) # Get modification date of file
sleep $SLEEP_TIME_MODIFICATION_FILE
# Get date later in seconds
TIME_SCREEN_LOG_FILE_LATER_IN_SECONDS=$(stat -c %Y ~/screenlog.0) # Get modification date of file
else
# Set this vars to 0 in case screenlog.0 file does not exist so simulates that the file does not exist
TIME_SCREEN_LOG_FILE_NOW_IN_SECONDS=0
TIME_SCREEN_LOG_FILE_LATER_IN_SECONDS=0
fi
# screenlog.0 file was updated in these last few secons?
if [[ $TIME_SCREEN_LOG_FILE_LATER_IN_SECONDS -gt $TIME_SCREEN_LOG_FILE_NOW_IN_SECONDS ]]; then # Most likely user is using -L with screen
# and I'll try to collect some data
# I don't see any valuable information than the total hashrate (I'll show a few at last)
# Surprise!!!, sed 's/ /\n/g' no convierte espacios en saltos de linea, pero la misma linea en la consola si lo hace!!!
TOTAL_HASHRATE=$(tail -60 ~/screenlog.0 | grep "Mining on PoWhash" | cut -d":" -f4 | cut -d" " -f2 | sed 's/ /\n/g' | tail -$GENOIL_NUMBER_OF_HASHRATES_TO_SHOW)
if [[ -z $TOTAL_HASHRATE ]]; then
TOTAL_HASHRATE="No data available"
fi
# Mount the little thing Genoil gives us
#
echo "Latest total hashrates : " >> ~/kk003_telegram_data/files/miner_statics.txt
echo $TOTAL_HASHRATE >> ~/kk003_telegram_data/files/miner_statics.txt
echo "Latest total hashrates : " >> ~/kk003_telegram_data/files/miner_statics_log_file.txt
echo $TOTAL_HASHRATE >> ~/kk003_telegram_data/files/miner_statics_log_file.txt
else
if [[ "$SEND_WARNING_WHEN_NO_L_ON_SCREEN" == "YES" ]]; then
MSG_NO_L_SCREEN="WARNING: It seems that you are not using -L with screen when starting the miner. Use -L with screen for this miner to be logged. Do this in 3main file: screen -dmSL miner <arguments>"
echo $MSG_NO_L_SCREEN
echo $MSG_NO_L_SCREEN >> ~/kk003_telegram_data/files/miner_statics.txt
echo $MSG_NO_L_SCREEN >> ~/kk003_telegram_data/files/miner_statics_log_file.txt
SEND_WARNING=1
fi
fi
else
echo "Genoil does not seem to be running!!. Skiping this bit."
GENOIL_IS_RUNNING="NO"
fi
fi
}
function ethminer_statics ()
{
#### Arrange the output for ethminer statics
if [[ "$ETHMINER_or_GENOIL_or_CLAYMORE" == "ETHMINER" ]]; then
# Check if ethminer is really running. Note that I have to search the full path as there is a few miners with the same exec's name
# Here I have to miner for ethminer
ps aux | grep -v grep | grep miner | grep -q "$KEY_ETHMINER_1"
RESP_CODE_1=$?
ps aux | grep -v grep | grep miner | grep -q "$KEY_ETHMINER_2"
RESP_CODE_2=$?
if [[ $RESP_CODE_1 -eq 0 || $RESP_CODE_2 -eq 0 ]]; then
ETHMINER_IS_RUNNING="YES"
KNOWN_MINER_RUNNING=1 # 1= I known this miner
ETHMINER_NUMBER_OF_HASHRATES_TO_SHOW=3 # Default 3, and I want to keep this value independent for each miner
echo ""
echo "It seems that ETHMINER is running!!"
# Clear the files
> ~/kk003_telegram_data/files/miner_statics.txt
> ~/kk003_telegram_data/files/miner_statics_log_file.txt
# Insert ethminer's header
echo "" >> ~/kk003_telegram_data/files/miner_statics.txt
echo "-- Ethminer mining Information :" >> ~/kk003_telegram_data/files/miner_statics.txt
echo "" >> ~/kk003_telegram_data/files/miner_statics_log_file.txt
echo "-- Ethminer mining Information :" >> ~/kk003_telegram_data/files/miner_statics_log_file.txt
# Extract the output from screen ---> I have tested this method all night long and it is UNSTABLE. At any given moment it stops writing the file.
# > ~/kk003_telegram_data/files/output_miner_from_screen
# TIMEOUT_FOR_TIMEOUT_IN_SECONDS=20 # The timeout for the command timeout to wait
# echo "Running timeout+script+screen for $TIMEOUT_FOR_TIMEOUT_IN_SECONDS seconds"
# timeout $TIMEOUT_FOR_TIMEOUT_IN_SECONDS script -q ~/kk003_telegram_data/files/output_miner_from_screen --command "screen -dr miner"
# sleep 2
# screen -d miner # does not seem to need to be Detached
# Check if user is currently using option -L with screen when he started the miner and get statics from screenlog.o file
if [[ -f ~/screenlog.0 ]]; then
SLEEP_TIME_MODIFICATION_FILE=10 # Hope 10 segs is enough for screen to write new data and save the file
# Get date now in seconds
TIME_SCREEN_LOG_FILE_NOW_IN_SECONDS=$(stat -c %Y ~/screenlog.0) # Get modification date of file
sleep $SLEEP_TIME_MODIFICATION_FILE
# Get date later in seconds
TIME_SCREEN_LOG_FILE_LATER_IN_SECONDS=$(stat -c %Y ~/screenlog.0) # Get modification date of file
else
# Set this vars to 0 in case screenlog.0 file does not exist so simulates that the file does not exist
TIME_SCREEN_LOG_FILE_NOW_IN_SECONDS=0
TIME_SCREEN_LOG_FILE_LATER_IN_SECONDS=0
fi
# screenlog.0 file was updated in these last few secons?
if [[ $TIME_SCREEN_LOG_FILE_LATER_IN_SECONDS -gt $TIME_SCREEN_LOG_FILE_NOW_IN_SECONDS ]]; then # Most likely user is using -L with screen
# and I'll try to collect some data
# I don't see any valuable information than the total hashrate (I'll show a few at last)
# Surprise!!!, sed 's/ /\n/g' no convierte espacios en saltos de linea, pero la misma linea en la consola si lo hace!!!
TOTAL_HASHRATE=$(tail -60 ~/screenlog.0 | grep "Mining on" | cut -d":" -f4 | cut -d" " -f2 | sed 's/ /\n/g' | tail -$ETHMINER_NUMBER_OF_HASHRATES_TO_SHOW)
if [[ -z $TOTAL_HASHRATE ]]; then
TOTAL_HASHRATE="No data available"
fi
# Mount the little thing ethminer gives us
#
echo "Latest total hashrates : " >> ~/kk003_telegram_data/files/miner_statics.txt
echo $TOTAL_HASHRATE >> ~/kk003_telegram_data/files/miner_statics.txt
echo "Latest total hashrates : " >> ~/kk003_telegram_data/files/miner_statics_log_file.txt
echo $TOTAL_HASHRATE >> ~/kk003_telegram_data/files/miner_statics_log_file.txt
else
if [[ "$SEND_WARNING_WHEN_NO_L_ON_SCREEN" == "YES" ]]; then
MSG_NO_L_SCREEN="WARNING: It seems that you are not using -L with screen when starting the miner. Use -L with screen for this miner to be logged. Do this in 3main file: screen -dmSL miner <arguments>"
echo $MSG_NO_L_SCREEN
echo $MSG_NO_L_SCREEN >> ~/kk003_telegram_data/files/miner_statics.txt
echo $MSG_NO_L_SCREEN >> ~/kk003_telegram_data/files/miner_statics_log_file.txt
SEND_WARNING=1
fi
fi
else
echo "Ethminer does not seem to be running!!. Skiping this bit."
ETHMINER_IS_RUNNING="NO"
fi
fi
}
function claymore_statics ()
{
#### Arrange the output for claymore statics
if [[ "$ETHMINER_or_GENOIL_or_CLAYMORE" == "CLAYMORE" ]]; then
# Check if claymore is running
if pgrep -x "$KEY_CLAYMORE" > /dev/null
then
CLAYMORE_IS_RUNNING="YES"
KNOWN_MINER_RUNNING=1 # 1= I known this miner
CLAYMORE_NUMBER_OF_HASHRATES_TO_SHOW=3 # Default 3, and I want to keep this value independent for each miner
echo
echo "It seems that Claymore is running!!"
#
# Don't know why http://localhost:3333 access forces claymore's output to show up a line like:
# "GPU #XX: GeForce GTX 1060 3GB, 3013 MB available, 9 compute units, capability: 6.1", one line x gpu in the system
# Get the latest total hashrates
LATEST_TOTAL_HASHRATES=`curl -s http://localhost:3333 | sed '/Total/!d; /Speed/!d;' | cut -d":" -f 2 | sed 's/ //g' | cut -d"," -f1 | tail -n 3`
echo "$LATEST_TOTAL_HASHRATES" > ~/kk003_telegram_data/files/latest_total_hashrates.txt
echo "$LATEST_TOTAL_HASHRATES" > ~/kk003_telegram_data/files/latest_total_hashrates_log_file.txt
# I want total hasrates on one line ("sed" cannot do this job so I use "tr" instead)
tr '\n' ' ' < ~/kk003_telegram_data/files/latest_total_hashrates.txt > ~/kk003_telegram_data/files/latest_total_hashrates.txt.tmp
# Remove last character (wich is a ",")
# sed -i 's/.$//' ~/kk003_telegram_data/files/latest_total_hashrates.txt.tmp
echo >> ~/kk003_telegram_data/files/latest_total_hashrates.txt.tmp
mv ~/kk003_telegram_data/files/latest_total_hashrates.txt.tmp ~/kk003_telegram_data/files/latest_total_hashrates.txt
cp ~/kk003_telegram_data/files/latest_total_hashrates.txt ~/kk003_telegram_data/files/latest_total_hashrates_log_file.txt
# Insert header on top of file
sed -i "1s/^/Latest Total Hashrates :\n/" ~/kk003_telegram_data/files/latest_total_hashrates.txt
sed -i "1s/^/Latest Total Hashrates :\n/" ~/kk003_telegram_data/files/latest_total_hashrates_log_file.txt
# Get the indivual gpus hashrates and remove some charaters and spaces I don't want
GPUS_HASHRATES=`curl -s http://localhost:3333 | sed '/ETH: GPU/!d' | awk 'NR == 3' | sed 's/[^GPU]*\(GPU.*\)/\1/' | sed 's/ M/M/g' | sed 's/ G/G/g'`
# Make the string with individual hashrates vertical replacing "," for new line "\n" and removing the "GPUX" part
echo $GPUS_HASHRATES | sed "s/,/\n/g" | sed 's/^[^ ]* //' > ~/kk003_telegram_data/files/gpus_hashrate.txt
echo $GPUS_HASHRATES | sed "s/,/\n/g" | sed 's/^[^ ]* //' > ~/kk003_telegram_data/files/gpus_hashrate_log_file.txt
# Get total individual and rejected shares and for how long claymore is runing in one single string
# For 13 gpus should look something like this:
# Speed: 318.710 Mh/s, Total Shares: 15835(1233+1212+1226+1256+1216+1243+1228+1303+1220+1177+1237+1209+1222), Rejected: 0, Time: 55:32
#
SOME_GPUS_DATA_FROM_CLAYMORE=`curl -s http://localhost:3333 | sed '/ETH - Total/!d; /Speed/!d; /(/!d; /+/!d; s/[^Speed]*\(Speed.*\)/\1/;' | awk 'NR == 3'`
# Get the total shares
TOTAL_SHARES=$(echo $SOME_GPUS_DATA_FROM_CLAYMORE | cut -d"(" -f 1 | cut -d" " -f 6)
# Get the individual shares (I capture the values between the two parentheses)
# and replace the "+" signs for new line so I set the data vertical
echo $SOME_GPUS_DATA_FROM_CLAYMORE | sed 's/^.*(//; s/).*$//; s/+/\n/g' > ~/kk003_telegram_data/files/individual_shares.txt
echo $SOME_GPUS_DATA_FROM_CLAYMORE | sed 's/^.*(//; s/).*$//; s/+/\n/g' > ~/kk003_telegram_data/files/individual_shares_log_file.txt
# Get the rejected shares and remove de ","
REJECTED_SHARES=$(echo $SOME_GPUS_DATA_FROM_CLAYMORE | cut -d" " -f 8 | sed 's/,//')
# How long claymore has been running?
TIME_CLAYMORE_IS_RUNNING=$(echo $SOME_GPUS_DATA_FROM_CLAYMORE | cut -d" " -f 10)
# Creating a vertical gpux list
# If the file exists and is not empty clear it
if [[ -s ~/kk003_telegram_data/files/v_gpus.txt ]]; then
> ~/kk003_telegram_data/files/v_gpus.txt
fi
if [[ -s ~/kk003_telegram_data/files/v_gpus_log_file.txt ]]; then
> ~/kk003_telegram_data/files/v_gpus_log_file.txt
fi
LINES_TO_ADD=$(($GPU_COUNT - 1))
for ((L=0; L <= $LINES_TO_ADD ; L=L+1))
do
case "$L" in
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 )
echo "GPU $L" >>~/kk003_telegram_data/files/v_gpus.txt
echo "GPU $L" >>~/kk003_telegram_data/files/v_gpus_log_file.txt
;;
*)
echo "GPU$L" >> ~/kk003_telegram_data/files/v_gpus.txt
echo "GPU$L" >> ~/kk003_telegram_data/files/v_gpus_log_file.txt
;;
esac
done
# Paste the whole vertical thing together
paste -d, ~/kk003_telegram_data/files/v_gpus.txt ~/kk003_telegram_data/files/individual_shares.txt ~/kk003_telegram_data/files/gpus_hashrate.txt > ~/kk003_telegram_data/files/miner_statics.tmp
paste -d, ~/kk003_telegram_data/files/v_gpus_log_file.txt ~/kk003_telegram_data/files/individual_shares_log_file.txt ~/kk003_telegram_data/files/gpus_hashrate_log_file.txt > ~/kk003_telegram_data/files/miner_statics_log_file.tmp
# Mount the header field for claymore statics
CLAYMOR_STATICS_HEADER="Index, Shares, Hashrate"
# Insert the whole header line as the first one
sed -i "1s/^/$CLAYMOR_STATICS_HEADER\n/" ~/kk003_telegram_data/files/miner_statics.tmp
sed -i "1s/^/$CLAYMOR_STATICS_HEADER\n/" ~/kk003_telegram_data/files/miner_statics_log_file.tmp
# Insert a new line on top
sed -i "1s/^/\n/" ~/kk003_telegram_data/files/miner_statics.tmp
sed -i "1s/^/\n/" ~/kk003_telegram_data/files/miner_statics_log_file.tmp
# Add the list of latest total hashrates and put it all togather
cat ~/kk003_telegram_data/files/latest_total_hashrates.txt ~/kk003_telegram_data/files/miner_statics.tmp > ~/kk003_telegram_data/files/miner_statics.txt
cat ~/kk003_telegram_data/files/latest_total_hashrates_log_file.txt ~/kk003_telegram_data/files/miner_statics_log_file.tmp > ~/kk003_telegram_data/files/miner_statics_log_file.txt
# Insert the Title for claymore mining information
sed -i "1s/^/-- Claymore mining Information :\n/" ~/kk003_telegram_data/files/miner_statics.txt
sed -i "1s/^/\n/" ~/kk003_telegram_data/files/miner_statics.txt
sed -i "1s/^/-- Claymore mining Information :\n/" ~/kk003_telegram_data/files/miner_statics_log_file.txt
sed -i "1s/^/\n/" ~/kk003_telegram_data/files/miner_statics_log_file.txt