From ceb99289cdfa9ddbcd892cde3345186684be3d98 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 20 Jun 2018 22:55:29 +0200 Subject: [PATCH] first version --- bp-position-daemon.sh | 119 ++++++++++++++++++++++++++++++++++++++++++ start.sh | 18 +++++++ stop.sh | 32 ++++++++++++ 3 files changed, 169 insertions(+) create mode 100755 bp-position-daemon.sh create mode 100755 start.sh create mode 100755 stop.sh diff --git a/bp-position-daemon.sh b/bp-position-daemon.sh new file mode 100755 index 0000000..f9453e6 --- /dev/null +++ b/bp-position-daemon.sh @@ -0,0 +1,119 @@ +#!/bin/bash +################################################################################ +# +# EOS BP Position Monitor +# Daemon that sends pm in telegram using bot functionality on changing position +# +# Created by http://CryptoLions.io +# +# Git Hub: https://github.com/CryptoLions/BP-Position-Telegram-Notifier +# Eos Network Monitor: http://eosnetworkmonitor.io/ +# +############################################################################### + + +#-- Config ------------------------------ + +# for what name moniotr position +PRODUCER_NAME_CHECK="cryptolions1" + + +# Register your Telegram Bot here @BotFather and get your Bot Token like 46354643:JHASDGFJSDJS-dsfdjhf +TELEGRAM_BOT_ID="" + +# Users telegram IDS. All who open joined your bot will leave his IDs here "https://api.telegram.org/bot"+BOT_ID+"/getUpdates" +TELEGRAM_CHAT_IDS=("5111111111" "5222222222") + +# time between check system contract in seconds +TIME_BETWEEN_CHECKS=5 + +# Name of log file +LOG_FILE="log_PlaceMonitor.log" + +# Path to you cleos wrapper +CLEOS=/var/www/JungleMonitor/scripts/cleos.sh + + +#----------------------------------------------------------------------- +#----------------------------------------------------------------------- +TELEGRAM_API="https://api.telegram.org/bot" +TELEGRAM_SEND_MSG="$TELEGRAM_API$TELEGRAM_BOT_ID/sendMessage" + +sendmessage(){ + for i in "${TELEGRAM_CHAT_IDS[@]}" + do + curl $TELEGRAM_SEND_MSG -X POST -d 'chat_id='$i'&text='"$1" >/dev/null 2>/dev/null + done +} + + +#===================================================================== +#===================================================================== + +LAST_POSITION=27; + +while true; do + + PROD_LIST=$($CLEOS system listproducers -l 50) + DATE=`date -d "now" +'%Y.%m.%d %H:%M:%S'` + POSITION=-1; + + while read -r line + do + #echo $line + POSITION=$(($POSITION+1)) + + data=($line) + + NAME=${data[0]}; + PROC=${data[${#data[@]}-1]}; + + MSG2=""; + if [[ "$NAME" == "$PRODUCER_NAME_CHECK" ]]; then + + if [[ $POSITION != $LAST_POSITION && $LAST_POSITION != -1 ]]; then + + SYMBOL="▲" + if [[ $POSITION > $LAST_POSITION ]]; then + SYMBOL="▼" + fi + MSG="$SYMBOL $DATE: Position Changed $LAST_POSITION -> $POSITION - $PROC %" + + + # in case you move to top 21 from standby + if [[ $LAST_POSITION -gt 21 && $POSITION -le 21 ]]; then + MSG2="✈ Be ready you are in top 21! You will start producing soon (in 2-3 rounds)" + fi + + # in case you move out from top 21 to standby + if [[ $LAST_POSITION -le 21 && $POSITION -gt 21 ]]; then + MSG2="💤 your node moved to stadnby" + fi + + + echo $MSG >> $LOG_FILE + + + sendmessage "$MSG" + if [[ "$MSG2" != "" ]]; then + echo $MSG2 >> $LOG_FILE + sleep 1 + sendmessage "$MSG2" + fi + #echo "--" >> $LOG_FILE + + LAST_POSITION=$POSITION + + break + fi + fi + done < <(printf '%s\n' "$PROD_LIST") + + sleep $TIME_BETWEEN_CHECKS; +done + + + + + + diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..02bb606 --- /dev/null +++ b/start.sh @@ -0,0 +1,18 @@ +#!/bin/bash +################################################################################ +# +# EOS BP Position Monitor +# Daemon that sends pm in telegram using bot functionality on changing position +# +# Created by http://CryptoLions.io +# +# Git Hub: https://github.com/CryptoLions/BP-Position-Telegram-Notifier +# Eos Network Monitor: http://eosnetworkmonitor.io/ +# +############################################################################### + +DATADIR="./" + +./stop.sh +./bp-position-daemon.sh & echo $! > $DATADIR/placeChecker.pid + diff --git a/stop.sh b/stop.sh new file mode 100755 index 0000000..60a5575 --- /dev/null +++ b/stop.sh @@ -0,0 +1,32 @@ +#!/bin/bash +################################################################################ +# +# EOS BP Position Monitor +# Daemon that sends pm in telegram using bot functionality on changing position +# +# Created by http://CryptoLions.io +# +# Git Hub: https://github.com/CryptoLions/BP-Position-Telegram-Notifier +# Eos Network Monitor: http://eosnetworkmonitor.io/ +# +############################################################################### + +DIR="./" + + + if [ -f $DIR"/placeChecker.pid" ]; then + pid=`cat $DIR"/placeChecker.pid"` + echo $pid + kill $pid + rm -r $DIR"/placeChecker.pid" + + echo -ne "Stoping Daemon" + + while true; do + [ ! -d "/proc/$pid/fd" ] && break + echo -ne "." + sleep 1 + done + echo -ne "\rDaemon Stopped. \n" + fi +