#!/bin/bash refname="https://g1.cgeek.fr" date=$(date '+%d-%m-%y à %H:%M') echo "############################" echo "$date" rep="/home/poka/scripts" lock=0 lockSync="/home/poka/scripts/lock-sync" [[ -n $lockSync ]] && touch $lockSync PID=$(ps auxf | grep "duniter" | grep -v -E "color=auto|grep|restart" | awk '{ print $2 }') PID=($(echo "$PID" | tr '\n' ' ')) if [[ -z $PID ]]; then $rep/duniter-restart.sh actionAlerte="redémarré" sendalerte exit 0 fi pokaNode=$(curl -s http://192.168.9.54:45000/blockchain/current | jq '.number') refNode=$(curl -s $refname/blockchain/current | jq '.number') [[ -e $lockSync ]] && lock=$(cat $lockSync) if [[ -z $pokaNode ]]; then if [[ $lock > 3 ]]; then rm $lockSync touch $lockSync diffNode=6 else ((lock++)) echo $lock > $lockSync diffNode=0 fi else [[ $(cat $lockSync) != 0 ]] && echo 0 > $lockSync diffNode=$(($refNode - $pokaNode)) fi checkg1() { echo "Mon noeud est au block $pokaNode tandi que le noeud $refName est à $refNode" if [[ $pokaNode < $refNode ]]; then echo "Mon noeud est à la bourre, il a $diffNode blocks de retard ..." else echo "Tout est bon!" fi } sendalerte() { TO="poka@p2p.legal" date=$(date +"%Hh%M") mutt -e "set from='duniter-g1@p2p.legal'" -e "set content_type=text/html" -e "set charset=UTF-8" -s "Alerte noeud ğ1 resync à $date !" $TO <

Le noeud ğ1 de Poka a été $actionAlerte


Par précaution, ce scrip a été locké $lock fois. MAIL_END } checkg1 #sendalerte if [[ $1 == "auto" ]]; then if [ $diffNode -gt 5 ]; then actionAlerte="resynchronisé" sendalerte bash $rep/duniter-resync.sh > /dev/null 2>&1 else exit 0 fi fi exit 0