-
Notifications
You must be signed in to change notification settings - Fork 1
/
amcli
executable file
·98 lines (83 loc) · 2.53 KB
/
amcli
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
#!/bin/bash
# Cli tool to for convenient monitor important Antminer S9 stats using curl and jq
# If it's not working check that API is enabled on miner (cat /config/bmminer.conf)
MINER_IP=192.168.0.105
USER=root
PASS=root
convertsecs() {
((h=${1}/3600))
((m=(${1}%3600)/60))
printf "%01d:%02d\n" $h $m
}
jqdashboard() {
STATUS="$(curl -H 'Cache-Control: no-cache' --digest -s --user root:root http://${MINER_IP}/cgi-bin/get_miner_status.cgi)";
SYS="$(curl -H 'Cache-Control: no-cache' --digest -s --user root:root http://${MINER_IP}/cgi-bin/get_system_info.cgi)"
TEMP="$(echo ${STATUS} | jq '{ temp: [ .devs[] | .temp ] | join(" ") }')"
SUMM="$(echo ${STATUS} | jq '.summary | with_entries(select([.key] | inside(["ghs5s", "ghsav", "accepted", "rejected"])))')"
MINERTIME="$( convertsecs $(echo ${STATUS} | jq '.summary.elapsed | tonumber') | jq --raw-input '{elapsed: '.'}')"
SYS_IMPORTANT="$(echo ${SYS} | jq 'with_entries(select([.key] | inside(["uptime", "loadaverage", "accepted"])))')"
echo "${MINERTIME} ${SYS_IMPORTANT} ${TEMP} ${SUMM}" | jq -s add
}
usage() {
echo "Usage: $0 [-h] [-v] [-r] [-l]"
echo " -h Help. Display this message and quit"
echo " -v Version. Print version number and quit"
echo " -a Show Antminer API authorization details"
echo " -r Reboot Antminer"
echo " -l Show Antminer linux kernel log"
echo "Without any option specified it's showing json dashboard"
exit
}
if ! [ -x "$(command -v curl)" ]; then
echo 'Error: curl is not installed.' >&2
exit 1
fi
if ! [ -x "$(command -v jq)" ]; then
echo 'Error: jq is not installed.' >&2
exit 1
fi
# ping return non-zero exit code if host is not available
if [ "`ping -c 1 ${MINER_IP} &> /dev/null`" ]; then
echo "${MINER_IP} is not available"
exit 1
fi
if [[ $# -eq 0 ]] ; then
jqdashboard
exit 0
fi
while (( $# > 0 ))
do
opt="$1"
shift
case $opt in
-h)
usage
exit 0
;;
--help)
usage
exit 0
;;
--version)
echo "$0 version 1.0"
exit 0
;;
-a)
echo "${USER}:${PASS}@${MINER_IP}"
exit 0
;;
-l)
curl -H 'Cache-Control: no-cache' --digest -s --user root:root http://${MINER_IP}/cgi-bin/get_kernel_log.cgi
exit 0
;;
-r)
curl --digest -s --user root:root http://${MINER_IP}/cgi-bin/reboot.cgi
exit 0
;;
*)
echo "Invalid option: '$opt'" >&2
usage
exit 1
;;
esac
done