-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathreport_alive.sh
executable file
·74 lines (63 loc) · 2.13 KB
/
report_alive.sh
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
#!/bin/bash
# this script can be used for check komodo daemon alive on your node
# and report via Telegram bot.
# (c) Decker
date=$(date +"%F %T")
token=000000000:aaaaaaa-bbbbbbbbbbbbbbbbbbbbbbbbbbb # your telegram bot token
chat_id=0 # telegram chat_id to report
proxy="-x socks5h://x.x.x.x:1080 --proxy-user user:proxypass" # proxy args for curl, if needed,
komodo_cli="$HOME/komodo/src/komodo-cli"
function init_colors () {
RESET="\033[0m"
BLACK="\033[30m"
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
MAGENTA="\033[35m"
CYAN="\033[36m"
WHITE="\033[37m"
}
# --------------------------------------------------------------------------
function log_print() {
datetime=$(date '+%Y-%m-%d %H:%M:%S')
echo -e [$datetime] $1
}
# --------------------------------------------------------------------------
function check_for_daemon() {
#if [[ ! -z $1 && $1 != "KMD" ]]
if [ ! -z $1 ] && [ $1 != "KMD" ]
then
coin=$1
asset=" -ac_name=$1"
else
coin="KMD"
asset=""
fi
# command && echo OK || echo Failed
# http://mywiki.wooledge.org/BashGuide/TestsAndConditionals
# https://www.opennet.ru/docs/RUS/bash_scripting_guide/c2171.html
#$komodo_cli $asset getinfo >/dev/null 2>&1
result=$($komodo_cli $asset getinfo 2>&1) # save both stdout and stderr to a variable
error=$?
if [ $error -eq 0 ]; then
log_print "\x5B${YELLOW}${coin}${RESET}\x5D ${GREEN}OK${RESET}"
else
log_print "\x5B${YELLOW}${coin}${RESET}\x5D ${RED}$result${RESET}"
fi
if [ $error -ne 0 ]; then
nl=$'\n'
text="<b>node report</b> (${date})${nl}"
text="${text}⚠️ ${coin} ${result}${nl}"
# echo -e "\"$text\""
curl -X POST -s $proxy "https://api.telegram.org/bot$token/sendMessage" -d "chat_id=$chat_id&parse_mode=HTML&text=$text" > /dev/null
fi
}
init_colors
# check_for_daemon KMD
readarray -t kmd_coins < <(curl -s https://raw.githubusercontent.com/jl777/komodo/beta/src/assetchains.json | jq -r '[.[].ac_name] | join("\n")')
kmd_coins+=(KMD)
for i in "${kmd_coins[@]}"
do
check_for_daemon $i
done