#!/bin/sh # # Variables courantes du programme # version="1.05" indice="c" model=`/bin/get_key_value /etc/synoinfo.conf upnpmodelname` heure=`date +%Hh%M` jour=`date +%d-%b-%Y` script=`ps | grep "^ *"$$ | sed -e 's/^..*sh //' | awk '{print $1}'` # # Cas ou 'rrdtool' n'est pas installe par IPKG # if test -f /lib/rrdtool.ttf then RRD_DEFAULT_FONT="/lib/rrdtool.ttf" export RRD_DEFAULT_FONT fi # bold="\033[1m" an="\033[0m" clear printf "#################### TPS version "$bold$version$indice$an" ###########################\n\n" # #======================================== # Verification si le script ne tourne pas # dans un autre process #======================================== if test "$1" != "info" then if test -f /tmp/tps-pid then printf "\n!! Attention !!\n\n" printf " Le script tourne actuellement dans un autre process.\n" printf " Veuiller attendre quelques secondes avant de le relancer\n" printf " ou bien lander le script avec l'option 'info' pour\n" printf " le debloquer\n\n" exit 0 else echo $$ > /tmp/tps-pid fi fi #======================================== # Test si les paquets IPKG sont Installés #======================================== # ipkg=`smartctl 2> /dev/null` if test "$ipkg" != "" then printf $script"-> \c" else echo "ERREUR le paquet IPKG smartmontools n'ai pas installé" echo "ce script ne foncrionnera pas sans celui-ci." rm -f /etc/tps.conf /etc/tps.log /etc/tps.rrd /etc/tps.esmtp rm -f /tmp/tps-pid exit 0 fi # ipkgesmtp=`esmtp -bp 2> /dev/null` ipkgrrdtool=`rrdtool 2> /dev/null` # #===================================== # Creation du fichier de configuration # si il n'existe pas => /etc/tps.conf #===================================== # if test -f /etc/tps.conf then #-------------------------- # Test si la version est OK #-------------------------- tpsversion=`/bin/get_key_value /etc/tps.conf tps-version` if test "$version" != "$tpsversion" -o "$1" = "init" then printf "Nouvelle version, initialisation de l'installation \n" tpsdossier=`/bin/get_key_value /etc/tps.conf tps-dossier` rm -f /etc/tps.conf /etc/tps.log /etc/tps.rrd /etc/tps.esmtp if test -f /etc/rc.local then cat /etc/rc.local | grep -v $script > /etc/rc.local fi config="oui" fi else config="oui" fi #----------------------------------------------------------- # Configuration auto si la version a change ou si le fichier # de configuration /etc/tps.conf n'existe pas #----------------------------------------------------------- if test "$config" = "oui" then echo "#--------------------------------------#" > /etc/tps.conf echo "# Fichier de Config script "$script >> /etc/tps.conf echo "#--------------------------------------#" >> /etc/tps.conf printf "tps-version=\""$version"\"\n#\n" >> /etc/tps.conf # if test "$ipkgesmtp" != "" then echo "tps-mail=\"oui\"" >> /etc/tps.conf else echo "tps-mail=\"non\"" >> /etc/tps.conf fi echo "tps-smtp=\""`/bin/get_key_value /etc/synoinfo.conf eventsmtp`"\"" >> /etc/tps.conf echo "hostname = "`/bin/get_key_value /etc/synoinfo.conf eventsmtp`":25" > /etc/tps.esmtp echo "tps-adre=\""`/bin/get_key_value /etc/synoinfo.conf eventmail1`"\"" >> /etc/tps.conf echo "tps-user=\""`/bin/get_key_value /etc/synoinfo.conf eventuser`"\"" >> /etc/tps.conf echo "tps-pass=\""`/bin/get_key_value /etc/synoinfo.conf eventpass`"\"" >> /etc/tps.conf # if test "$ipkgrrdtool" != "" then echo "tps-graph=\"oui\"" >> /etc/tps.conf else echo "tps-graph=\"non\"" >> /etc/tps.conf fi echo "tps-texte=\"oui\"" >> /etc/tps.conf if test "$tpsdossier" = "" then tpsdossier="/volume1/web" fi if test -d $tpsdossier then echo "tps-dossier=\""$tpsdossier"\"" >> /etc/tps.conf else echo "tps-dossier=\"/tmp\"" >> /etc/tps.conf fi tpsiptest=`/bin/get_key_value /etc/synoinfo.conf eventsmtp` echo "tps-iptest=\""$tpsiptest"\"" >> /etc/tps.conf # printf "#\n# Temperature Critique\ntps-criti=\"55-3-0\"\n" >> /etc/tps.conf printf "#\ntps-temps=\"5\"\n#\n# Variables courantes\n#\ntps-jour=\""$jour"\"\n#\n" >> /etc/tps.conf # fi #=================================== # Menu de configuration du script # Cas ou on lance 'tps config' # ou si premiere execution su script #=================================== # if test "$1" = "config" -o "$config" = "oui" -o "$1" = "info" then status=`cat /etc/crontab | grep $script | sed -e "s/^.*root.*sh //"` if test "$status" = "$script" then status="Actif" #------------------------------------------------------------- # On stop temporairement l'execution du script dans le Crontab # cas ou on est en phase de configuration. #------------------------------------------------------------- if test "$1" = "config" -o "$config" = "oui" then killall crond cat /etc/crontab | grep -v $script > /etc/crontab sleep 1 /usr/sbin/crond fi else status="Desactive" fi #----------------------------- # recup des valeurs par defaut #----------------------------- tpsmail=`/bin/get_key_value /etc/tps.conf tps-mail` tpssmtp=`/bin/get_key_value /etc/tps.conf tps-smtp` tpsadre=`/bin/get_key_value /etc/tps.conf tps-adre` tpsuser=`/bin/get_key_value /etc/tps.conf tps-user` tpspass=`/bin/get_key_value /etc/tps.conf tps-pass` # tpsgraph=`/bin/get_key_value /etc/tps.conf tps-graph` tpstexte=`/bin/get_key_value /etc/tps.conf tps-texte` tpsdossier=`/bin/get_key_value /etc/tps.conf tps-dossier` tpstemps=`/bin/get_key_value /etc/tps.conf tps-temps` tpsiptest=`/bin/get_key_value /etc/tps.conf tps-iptest` # tpscriti=`/bin/get_key_value /etc/tps.conf tps-criti` tpscritt=`echo $tpscriti | awk -F- '{print $1}'` tpscritn=`echo $tpscriti | awk -F- '{print $2}'` jourlog=`/bin/get_key_value /etc/tps.conf tps-jour` #----------------------------- # Affiche les infos de config #----------------------------- if test "$1" = "info" then clear echo -e "#################### TPS version "$bold$version$indice$an" ###########################" echo "" echo $script" config => configuration du script" echo $script" stop => suspendre les releves / desactive le script" echo $script" start => reprendre les releves / active le script" echo $script" info => informe sur l'etat du script" echo $script" mail => envoie un rapport par mail immediatement" echo $script" init => force l'initialisation du script" echo $script" => genere un releve dans la base de donne" echo "" connect=`ping -c 1 $tpsiptest 2> /dev/null | grep -i " 0% packet loss"` if test "$connect" = "" then testc="en echec" else testc="OK" fi echo "Envoie de mails => "$tpsmail" Test de connexion "$testc" sur "$tpsiptest echo "Parametres MAIL => "$tpsadre" sur "$tpssmtp if test "$user" = "" then user="##" fi if test "$pass" = "" then pass="##" fi echo " USER / PASS => "$user"/"$pass" utile chez des F.A.I. comme 'laposte.net'" echo "Creation graph => "$tpsgraph echo "Creation texte => "$tpstexte echo "Dossier img/txt => "$tpsdossier echo "Temperature maxi => "$tpscritt"° arret apres "$tpscritn" mesures consecutives" echo "Intervalle temps => "$tpstemps" minutes" echo "Jour courant => "$jourlog printf "Status du script => "$bold$status$an if test "$status" != "Actif" then echo -e " <-pour activer-> "$bold$script" start"$an else echo fi echo rm -f /tmp/tps-pid exit 0 fi #---------------------------------- # Changement de config pour le mail #---------------------------------- if test "$ipkgesmtp" != "" then echo printf "Envoie du Mail oui/non : ("$tpsmail") \c" ; read q if test "$q" != "" then tpsmail=$q cat /etc/tps.conf | sed -e 's/tps-mail=".*"/tps-mail="'$tpsmail'"/' > /etc/tps.conf fi if test "$tpsmail" = "oui" -o "$tpsmail" = "OUI" then printf "Adresse de messagerie : ("$tpsadre") \c" ; read q if test "$q" != "" then tpsadre=$q cat /etc/tps.conf | sed -e 's/tps-adre=".*"/tps-adre="'$tpsadre'"/' > /etc/tps.conf fi printf "Serveur de messagerie : ("$tpssmtp") \c" ; read q if test "$q" != "" then tpssmtp=$q cat /etc/tps.conf | sed -e 's/tps-smtp=".*"/tps-smtp="'$tpssmtp'"/' > /etc/tps.conf echo "hostname = "$tpssmtp":25" > /etc/tps.esmtp fi echo echo " - Utilisateur et mot de passe pour l'authentification du serveur" echo " de messagerie, necessaire chez certains F.A.I. comme 'laposte.net'" echo printf "Utilisateur SMTP : ("$tpsuser") \c" ; read q if test "$q" != "" then tpsuser=$q cat /etc/tps.conf | sed -e 's/tps-user=".*"/tps-user="'$tpsuser'"/' > /etc/tps.conf echo "username = \""$tpsuser"\"" >> /etc/tps.esmtp fi printf "Mot de passe SMTP : ("$tpspass") \c" ; read q if test "$q" != "" then tpspass=$q cat /etc/tps.conf | sed -e 's/tps-pass=".*"/tps-pass="'$tpspass'"/' > /etc/tps.conf echo "password = \""$tpspass"\"" >> /etc/tps.esmtp fi # connect=`ping -c 1 $tpsiptest 2> /dev/null | grep -i " 0% packet loss"` if test "$connect" = "" then testc="en-echec" else testc="OK" fi printf "\nTest de connexion "$testc" sur "$tpsiptest" : \c" ; read q if test "$q" != "" then tpsiptest=$q cat /etc/tps.conf | sed -e 's/tps-iptest=".*/tps-iptest="'$tpsiptest'"/' > /etc/tps.conf fi fi else cat /etc/tps.conf | sed -e 's/tps-mail=".*"/tps-mail="non"/' > /etc/tps.conf printf "\nL'utilitaire ESMTP n'ai pas installé, pas d'envoie de mail possible.\n\n" fi #----------------------------------- # Changement de config pour le graph #----------------------------------- if test "$ipkgrrdtool" != "" then printf "\nSuivi graphiquement oui/non : ("$tpsgraph") \c" ; read q if test "$q" != "" then tpsgraph=$q fi cat /etc/tps.conf | sed -e 's/tps-graph=".*"/tps-graph="'$tpsgraph'"/' > /etc/tps.conf else cat /etc/tps.conf | sed -e 's/tps-graph=".*"/tps-graph="non"/' > /etc/tps.conf printf "\nL'utilitaire RRDTOOL n'ai pas installé, pas de graphique possible.\n\n" fi #------------------------------------------------- # Changement de config pour le rapport par fichier #------------------------------------------------- printf "\nRapport fichier Txt oui/non : ("$tpstexte") \c" ; read q if test "$q" != "" then tpstexte=$q fi cat /etc/tps.conf | sed -e 's/tps-texte=".*"/tps-texte="'$tpstexte'"/' > /etc/tps.conf #---------------------------------------- # Config pour le dossier image et rapport #---------------------------------------- if test "$tpsgraph" = "oui" -o "$tpstexte" = "oui" then ok="no" while test "$ok" != "ok" do printf "\nDossier de stockage image/rapport txt : ("$tpsdossier") : \c" ; read q if test "$q" != "" then tpsdossier=$q fi if test -d $tpsdossier then ok="ok" else printf "\nErreur, le dossier de stockage n'existe pas !!\n\n" fi done tpsdossier="tps-dossier=\""`echo $tpsdossier | sed -e "s/\//slash/g"` cat /etc/tps.conf | sed -e 's/tps-dossier=".*/'$tpsdossier'"/' | sed -e "s/slash/\//g" > /tmp/tps-tmp mv /tmp/tps-tmp /etc/tps.conf fi #------------------------------------------- # Config pour la temperature critique # maxi du disque et le nombre pic admissible #------------------------------------------- echo echo " - Temperature critique maxi admissible par le(s) disque(s)" echo " Permet d'eteindre proprement le serveur en cas de défaut" echo " au niveau du refroidissement ou de la ventilation" echo " Cette valeur doit etre comprise entre 30° et 70°" printf "\nTemperature de securites maxi : ("$tpscritt") \c" ; read q q=`expr $q \* 1 2> /dev/null` if test "$q" != "" then tpscritt=$q fi if [ `expr $tpscritt \<= 30 ` -eq 1 ] then tpscritt="30" fi if [ `expr $tpscritt \>= 70 ` -eq 1 ] then tpscritt="70" fi # echo echo " - Nombre de pic de temperature critique avant arret du serveur" echo " Evite un arret en cas de pic temporaire" echo " Cette valeur doit etre superieure ou egale a 2" printf "\nNombre de maxi de pic : ("$tpscritn") \c" ; read q q=`expr $q \* 1 2> /dev/null` if test "$q" != "" then tpscritn=$q fi if [ `expr $tpscritn \<= 1 ` -eq 1 ] then tpscritn="2" fi cat /etc/tps.conf | sed -e 's/tps-criti=".*"/tps-criti="'$tpscritt'-'$tpscritn'-0"/' > /etc/tps.conf #----------------------------------- # Config de l'intervalle des releves #----------------------------------- echo echo " - Intervalle de temps entre chaque releve du script" echo " La valeur doit etre comprise entre 2 et 60 minutes" printf "\n Intervalle de releve : ("$tpstemps") \c" ; read q echo q=`expr $q \* 1 2> /dev/null` if test "$q" != "" then tpstemps=$q fi if [ `expr $tpstemps \<= 1 ` -eq 1 ] then tpstemps="2" fi if [ `expr $tpstemps \>= 60 ` -eq 1 ] then tpstemps="60" fi cat /etc/tps.conf | sed -e 's/tps-temps=".*"/tps-temps="'$tpstemps'"/' > /etc/tps.conf #--------------------------------------------- # On reprend l'execution du script # cas ou il etait actif avant la configuration #--------------------------------------------- if test "$status" = "Actif" then killall crond cat /etc/crontab | grep -v $script > /etc/crontab sleep 1 echo "*/"$tpstemps" * * * * root sh "$script >> /etc/crontab sleep 1 /usr/sbin/crond fi #------------------------------------------ # On relance le script avec l'option 'info' # pour avoir un recapitulatif de la config # puis arret. #------------------------------------------ $script info rm -f /tmp/tps-pid exit 0 fi #=============================== # Cas ou on lance le script avec # 'stop' ou 'start' #=============================== # if test "$1" = "stop" -o "$1" = "start" then killall crond /bin/cat /etc/crontab | grep -v $script > /etc/crontab # if test "$1" = "start" then tpstemps=`/bin/get_key_value /etc/tps.conf tps-temps` printf "Lancement du script toutes les "$tpstemps" minutes -> \c" echo "*/"$tpstemps" * * * * root sh "$script >> /etc/crontab fi #--------------------- # On relance crond # puis arret du script #--------------------- /usr/sbin/crond printf "\n\n"$script" action => "$1" OK\n\n" rm -f /tmp/tps-pid exit 0 fi #================================================================================================= # Releve la temperature des disques #================================================================================================= # cd /dev nbrdisk=0 for bo in `/bin/ls hd?` do t=`smartctl -A $bo | grep -i "194.*Celsius" | awk '{print $10}'` if test "$t" != "" then h=`smartctl -A $bo | grep -i " 9.*Power" | awk '{print $10}'` nbrdisk=`expr $nbrdisk + 1` temp=$temp" "$t dure=$dure" disk"$nbrdisk"= "$h" " fi done temp=`echo $temp | sed -e "s/^ //"` Tmax=`echo $temp | awk '{print $1"\n"$2"\n"$3"\n"$4}' | sort | tail -1` Tmin=`echo $temp | awk '{print $1"\n"$2"\n"$3"\n"$4}' | grep -v "^$" | sort -r | tail -1` delta=`expr $Tmax - $Tmin` Tmoy=`echo $temp | awk '{print ($1+$2+$3+$4)/'$nbrdisk' }'` #-------------------------------------------------- # Ecriture des donnees dans le fichier /etc/tps.log #-------------------------------------------------- echo "Moyenne="$Tmoy" Delta="$delta" Disques="$temp" "$heure >> /etc/tps.log echo echo "Température moyenne => "$Tmoy"° à "$heure" le "$jour echo "Température /disque(s) => "$temp" degrées" #--------------------------------------------- # Traitement texte, ecriture du dernier releve #--------------------------------------------- tpstexte=`/bin/get_key_value /etc/tps.conf tps-texte` if test "$tpstexte" = "oui" then tpstexte=`/bin/get_key_value /etc/tps.conf tps-dossier`"/tps-"`hostname`".log" echo "Température moyenne => "$Tmoy"° à "$heure" le "$jour > $tpstexte echo "Température /disque(s) => "$temp" degrées" >> $tpstexte fi #---------------------------------------- # Vérification de la temperature critique #---------------------------------------- tpscriti=`/bin/get_key_value /etc/tps.conf tps-criti` tpscritt=`echo $tpscriti | awk -F- '{print $1}'` tpscritn=`echo $tpscriti | awk -F- '{print $2}'` tpscritc=`echo $tpscriti | awk -F- '{print $3}'` # if [ `expr $Tmoy \>= $tpscritt ` -eq 1 ] then critc=`expr $tpscritc + 1` if [ `expr $critc \>= $tpscritn ` -eq 1 ] then mess="-> ATTENTION temperature Critique arret du SERVEUR" echo $mess echo `date +%b" "%_d" "%T`" "$script" "$mess >> /var/log/messages cat /etc/tps.conf | sed -e 's/tps-criti=".*"/tps-criti="'$tpscritt'-'$tpscritn'-0"/' > /etc/tps.conf rm -f /tmp/tps-pid sleep 2 echo " Arret du syno" busybox halt else cat /etc/tps.conf | sed -e 's/tps-criti=".*"/tps-criti="'$tpscritt'-'$tpscritn'-'$critc'"/' > /etc/tps.conf mess="-> ATTENTION temperature Critique. "$critc"/"$tpscritn" pics consecutifs" echo $mess echo `date +%b" "%_d" "%T`" "$script" "$mess >> /var/log/messages fi else if test "$tpscritc" != "0" then cat /etc/tps.conf | sed -e 's/tps-criti=".*"/tps-criti="'$tpscritt'-'$tpscritn'-0"/' > /etc/tps.conf echo "-> Remise a zero du compteur critique" fi fi #======================================================================== # Traitement graphique ************************************************** #======================================================================== tpsgraph=`/bin/get_key_value /etc/tps.conf tps-graph` if test "$tpsgraph" = "oui" then tpsdossier=`/bin/get_key_value /etc/tps.conf tps-dossier`"/tps-"`hostname`".png" tempsrdd=`rrdtool info /etc/tps.rrd 2> /dev/null | grep -i step | awk '{print $3 / 60}'` tpstemps=`/bin/get_key_value /etc/tps.conf tps-temps` # #--------------------------------------------------- # Test si la base existe et si l'intervalle de temps # et identique a l'intervalle des releves #--------------------------------------------------- if test "$tpstemps" = "$tempsrdd" then rrdtool update /etc/tps.rrd N:$Tmoy:$delta printf "Creation du graph \c" # #--------------------------------------------- # Generation du Graphique special Cube Station # avec 1 ou plusieurs disques #--------------------------------------------- if test "$model" = "CS-406" then # rrdtool graph $tpsdossier -w 600 -h 100 \ --title `hostname`" => SYNOLOGY "$model" le "$jour" "$heure \ --vertical-label "Degrees C°" \ --x-grid MINUTE:15:HOUR:1:HOUR:2:0:%Hh00 \ --imgformat PNG \ --color MGRID#337fbf \ --color FRAME#808080 \ --color ARROW#FF0099 \ DEF:disque=/etc/tps.rrd:disque:AVERAGE \ DEF:deltad=/etc/tps.rrd:deltad:AVERAGE \ CDEF:flaming1=disque,40,*,100,/ \ CDEF:flaming2=disque,5,*,100,/ \ AREA:flaming1#ffff5f \ STACK:flaming2#fffc51 \ STACK:flaming2#fffc51 \ STACK:flaming2#fff046 \ STACK:flaming2#ffe95f \ STACK:flaming2#ffd237 \ STACK:flaming2#ffc832 \ STACK:flaming2#ffbe2d \ STACK:flaming2#ffaa23 \ STACK:flaming2#ff9619 \ STACK:flaming2#ff841e \ STACK:flaming2#ff841e \ STACK:flaming2#ff6600:"Temperature disques" \ GPRINT:disque:MAX:"Max %2.0lf°" \ GPRINT:disque:MIN:"Min %2.0lf°" \ GPRINT:disque:AVERAGE:"Moyen %2.1lf°" \ GPRINT:deltad:AVERAGE:"Ecart maxi %2.1lf°" \ GPRINT:disque:LAST:"Derniere mesure %2.0lf° \n" \ COMMENT:"\n" \ COMMENT:" ---------------------------- \n" \ COMMENT:" Compteur horaire $dure" # # #--------------------------------------------- # Generation du Graphique pour les autres SYNO # avec 1 disque uniquement #--------------------------------------------- else ph=`echo $dure | awk '{print $2}'` testph=`expr $ph \* 1 2> /dev/null` if test "$testph" = "$ph" then txtph="heures" else txtph="" fi rrdtool graph $tpsdossier -w 600 -h 100 \ --title `hostname`" => SYNOLOGY "$model" le "$jour" "$heure \ --vertical-label "Degrees C°" \ --x-grid MINUTE:15:HOUR:1:HOUR:2:0:%Hh00 \ --imgformat PNG \ --color MGRID#337fbf \ --color FRAME#808080 \ --color ARROW#FF0099 \ DEF:disque=/etc/tps.rrd:disque:AVERAGE \ CDEF:flaming1=disque,40,*,100,/ \ CDEF:flaming2=disque,5,*,100,/ \ AREA:flaming1#ffff5f \ STACK:flaming2#fffc51 \ STACK:flaming2#fffc51 \ STACK:flaming2#fff046 \ STACK:flaming2#ffe95f \ STACK:flaming2#ffd237 \ STACK:flaming2#ffc832 \ STACK:flaming2#ffbe2d \ STACK:flaming2#ffaa23 \ STACK:flaming2#ff9619 \ STACK:flaming2#ff841e \ STACK:flaming2#ff841e \ STACK:flaming2#ff6600:"Temperature du disque" \ GPRINT:disque:MAX:"Max %2.0lf°" \ GPRINT:disque:MIN:"Min %2.0lf°" \ GPRINT:disque:AVERAGE:"Moyen %2.2lf°" \ GPRINT:disque:LAST:"Derniere mesure %2.0lf° ("$ph" "$txtph") " # fi # else echo "Initialisation de la base rrdtool" step=`expr $tpstemps \* 60` inte=`expr $step \* 2` rrdtool create /etc/tps.rrd -s $step \ DS:disque:GAUGE:$inte:U:U \ DS:deltad:GAUGE:$inte:U:U \ RRA:AVERAGE:0.5:1:288 fi fi # #====================================================================== # Traitement par Mail *********************************************** #====================================================================== # tpsmail=`/bin/get_key_value /etc/tps.conf tps-mail` if test "$tpsmail" = "oui" then # jourlog=`/bin/get_key_value /etc/tps.conf tps-jour` tpstemps=`/bin/get_key_value /etc/tps.conf tps-temps` # # test si le jour a change ou bien # si on a lance le script avec l'option mail # if test "$jourlog" != "$jour" -o "$1" = "mail" then echo "Preparation du mail" #----------------------------------------------- # Dans ce cas, on prepare le mail et on l'envoie #----------------------------------------------- /bin/cat /etc/tps.log | sed -e 's/ Delta.*//' | awk -F= '{print $2}' > /tmp/tps-moy.log /bin/cat /etc/tps.log | sed -e 's/ Disques.*//' | awk -F= '{print $3}' > /tmp/tps-del.log /bin/cat /etc/tps.log | sed -e 's/Moy.*Disques=//' | sed -e 's/ /°/g' | sed -e "s/[0-9][0-9]h/~&/" > /tmp/tps-disk0.log # if test "$model" = "CS-406" then tab="4" else tab="6" fi col="1" printf "=== Liste brut des releves du jour "$jourlog" ===\n\n" > /tmp/tps-disk.log for bo in `/bin/cat /tmp/tps-disk0.log` do if test "$col" != "$tab" then printf " "$bo" \c" >> /tmp/tps-disk.log else echo " "$bo >> /tmp/tps-disk.log col="0" fi col=`expr $col + 1` done #----------------------------- # Prepa entete du fichier mail #----------------------------- tpsadre=`/bin/get_key_value /etc/tps.conf tps-adre` echo "From: \"SYNO "`hostname`"\" <"$tpsadre">" > /tmp/ficmail echo "To: "`echo $tpsadre | awk -F@ '{print $1}'`"<"$tpsadre">" >> /tmp/ficmail echo "Subject: Diagnostique disque du "$jourlog >> /tmp/ficmail echo "X-Priority: 1" >> /tmp/ficmail echo "Content-Type: text/plain; charset=iso-8859-1" >> /tmp/ficmail echo "Content-Transfer-Encoding: 8bit" >> /tmp/ficmail echo "MIME-Version: 1.0" >> /tmp/ficmail echo "Date: "`date -R` >> /tmp/ficmail echo "" >> /tmp/ficmail #--------------------------------- # Infos SMART + Modele des disques #--------------------------------- cd /dev disque=0 > /tmp/tps-smart > /tmp/tps-disk # pour le CS-406 if test "$model" = "CS-406" then for bo in `/bin/ls hd?` do ph=`smartctl -A $bo | grep -i " 9.*Power" | awk '{ print $10 }'` if test "$ph" != "" then testph=`expr $ph \* 1 2> /dev/null` if test "$testph" = "$ph" then txtph=" heures" else txtph="" fi disque=`expr $disque + 1` pc=`smartctl -A $bo | grep -i "12.*Power" | awk '{ print $10 }'` echo "Valeurs S.M.A.R.T du DISQUE numero : "$disque" (/dev/"$bo")" >> /tmp/tps-smart echo " " >> /tmp/tps-smart smartctl -i $bo | grep -i "^[MDSU]" | grep -vi "smart" >> /tmp/tps-smart echo " " >> /tmp/tps-smart smartctl -A $bo | grep -i "ID#" >> /tmp/tps-smart smartctl -A $bo | grep -i "^ *[0-9][0-9]* ..* 0x0" >> /tmp/tps-smart echo "------------------------------------------------------------------------------------------------" >> /tmp/tps-smart echo " " >> /tmp/tps-smart echo "Disque n°"$disque" : "$ph$txtph" / "$pc" demarrages." >> /tmp/tps-disk fi done echo "=== Information de "`hostname`" avec "$disque" disque(s) le "$jourlog" ===" >> /tmp/ficmail # pour les autres syno else ph=`smartctl -A /dev/hda | grep -i " 9.*Power" | awk '{ print $10 }'` testph=`expr $ph \* 1 2> /dev/null` if test "$testph" = "$ph" then txtph=" heures" else txtph="" fi pc=`smartctl -A /dev/hda | grep -i "12.*Power" | awk '{ print $10 }'` printf "Valeurs S.M.A.R.T du DISQUE \n \n" >> /tmp/tps-smart smartctl -i /dev/hda | grep -i "^[MDSU]" | grep -vi "smart" >> /tmp/tps-smart echo " " >> /tmp/tps-smart smartctl -A /dev/hda | grep -i "ID#" >> /tmp/tps-smart smartctl -A /dev/hda | grep -i "^ *[0-9][0-9]* ..* 0x0" >> /tmp/tps-smart echo "------------------------------------------------------------------------------------------------" >> /tmp/tps-smart echo " " >> /tmp/tps-smart echo "Disque dur interne : "$ph$txtph" / "$pc" demarrages." >> /tmp/tps-disk echo "=== Information de "`hostname`" le "$jourlog" ===" >> /tmp/ficmail fi #------------------- # Info sur le reseau #------------------- infoeth=`synoethinfo | awk -F: '{print $2}'` macaddr=`ifconfig eth0 | grep HWaddr | sed -e "s/..*HWaddr //"` ip=`ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}` passerelle=`route | grep default | awk '{print $2}'` infoeth=`echo $infoeth | awk '{print $1" "$2" MTU="$3}'` # echo " " >> /tmp/ficmail /bin/cat /tmp/tps-disk >> /tmp/ficmail echo " " >> /tmp/ficmail #---------------------------------------------------------------- # Temperature moyenne, mini, maxi, Heure les plus chaudes du jour # Ecriture des infos #---------------------------------------------------------------- nbr=`wc -l /tmp/tps-moy.log | awk '{print $1}'` h=`echo $nbr | awk '{ print $1 / 60 * '$tpstemps'}' | awk -F. '{print $1}'` m=`echo $nbr | awk '{ print (( $1 / 60 * '$tpstemps' ) - '$h') * 60 }' | awk -F. '{print $1}'` Tmax=`cat /tmp/tps-moy.log | sort | tail -1` Tmin=`cat /tmp/tps-moy.log | sort -r | tail -1` HTmax=`cat /etc/tps.log | grep "Moyenne=$Tmax" | sed -e 's/^..* //'` up=`uptime | sed "s/^.*up *//" | sed "s/days*,/jours/" | sed "s/:/ heures /" | sed "s/ *m*i*n*,.*/ minutes/"` echo "Uptime du serveur : "$up >> /tmp/ficmail echo "Information reseau : "$infoeth" Passerelle : "$passerelle >> /tmp/ficmail echo "Adresse MAC : "$macaddr >> /tmp/ficmail echo "Panel 'admin' : http://"$ip":5000/" >> /tmp/ficmail echo " " >> /tmp/ficmail echo "Temps en fonction : "$h" h "$m" min <-ou-> "$nbr" releves" >> /tmp/ficmail # # pour le CS-406 # if test "$model" = "CS-406" then Delt=`cat /tmp/tps-del.log | sort | tail -1` for bou in `/bin/cat /tmp/tps-moy.log` do t=`echo $bou | awk -F. '{print $1}'` echo $t >> /tmp/tps.$t done echo "Temp. Moyenne Min : "$Tmin"°" >> /tmp/ficmail echo "Temp. Moyenne Max : "$Tmax"°" >> /tmp/ficmail echo "Ecart Maxi/Disque : "$Delt"°" >> /tmp/ficmail # # pour les autres # else Tmoy=0 for bou in `/bin/cat /tmp/tps-moy.log` do t=`echo $bou | awk -F. '{print $1}'` Tmoy=`expr $Tmoy + $t` echo $t >> /tmp/tps.$t done Tmoy=`echo $Tmoy | awk '{print $1 * 100 / '$nbr'}' | awk -F. '{print $1 / 100}'` echo "Temperature Mini : "$Tmin"°" >> /tmp/ficmail echo "Temperature Maxi : "$Tmax"°" >> /tmp/ficmail echo "Temperature Moyenne : "$Tmoy"°" >> /tmp/ficmail fi # echo " " >> /tmp/ficmail echo "Heure ++ chaudes : "$HTmax >> /tmp/ficmail echo " " >> /tmp/ficmail #---------------------- # Infos sur les volumes #---------------------- for bo in `/bin/ls / | grep volume` do info=`df -h /$bo 2> /dev/null | grep $bo` if test "$info" != "" then echo $info | awk '{print "Taux ~ utilisation. : "$2" - "$5" , "$4" libre pour '$bo'."}' >> /tmp/ficmail fi done #----------------------------------- # Tri du fichier de releve du jour # et Stat temperature en % du temps #----------------------------------- # echo " " >> /tmp/ficmail echo "=== Temperature en fonction du temps d utilisation ===" >> /tmp/ficmail echo " " >> /tmp/ficmail for bou in `/bin/ls /tmp/tps.*` do t=`echo $bou | awk -F. '{ print $2 }'` p=`wc -l $bou | awk '{print $1 * 10000 / '$nbr'}' | awk -F. '{print $1 / 100}'` nbcar=`echo $p | awk -F. '{print $1}' | wc -c | awk '{print $1 - 1}'` virgu=`echo $p | awk -F. '{print $2}' | wc -c | awk '{print $1 - 1}'` if test "$virgu" = "0" then p=$p".00" fi if test "$nbcar" = "1" then echo $t"° ~~> " $p"% " >> /tmp/ficmail else echo $t"° ~~> " $p"% " >> /tmp/ficmail fi done # echo " " >> /tmp/ficmail echo "======================================================" >> /tmp/ficmail # echo "http://"`hostname`"/tps-"`hostname`".png < en image" >> /tmp/ficmail echo "======================================================" >> /tmp/ficmail echo " " >> /tmp/ficmail /bin/cat /tmp/tps-smart >> /tmp/ficmail # /bin/cat /tmp/tps-disk.log | sed -e "s/~/ ~ /g" >> /tmp/ficmail #---------------------------------------------- # Importation des erreurs du jour contenus dans # le fichier /var/log/messages #---------------------------------------------- datelog=`echo $jourlog | awk -F- '{print $2" "$1" "}' | sed -e "s/ 0/ /"` m=`echo $datelog | awk '{print $1}'` j=`echo $datelog | awk '{print $2}'` echo " " >> /tmp/ficmail echo " " >> /tmp/ficmail echo "=== Erreurs du jour, du fichier /var/log/messages ===" >> /tmp/ficmail echo " " >> /tmp/ficmail cat /var/log/messages | grep -i "^$m *$j.*error" | cut -c+7- | sed -e "s/$/.\n./" | sed -e "s/: .*: /&\n/g" >> /tmp/ficmail echo "....." >> /tmp/ficmail cat /var/log/messages | grep -i "^$m *$j.*$script" | cut -c+7- | sed -e "s/$/.&/" >> /tmp/ficmail echo "....." >> /tmp/ficmail echo " " >> /tmp/ficmail echo "*** Fin de rapport le "$jour" a "$heure" 'tps' V"$version$indice" ***" >> /tmp/ficmail #------------------------------------------ # Envoie du Mail avec test si connection OK # sinon on sauvegarde le mail #------------------------------------------ tpsiptest=`/bin/get_key_value /etc/tps.conf tps-iptest` connect=`ping -c 1 $tpsiptest 2> /dev/null | grep -i " 0% packet loss"` # if test "$connect" != "" then echo "Envoie du mail à "$tpsadre esmtp -C /etc/tps.esmtp $tpsadre < /tmp/ficmail #---------------------- # envoie mail en retard #---------------------- for bou in `/bin/ls /etc/tps.mail* 2> /dev/null` do esmtp -C /etc/tps.esmtp $tpsadre < $bou echo "Envoie du mail en retard" $bou rm -f $bou done #--------------------------------------- # Sauvegarde du mail si pas de connexion #--------------------------------------- else echo "Envoie du mail à "$tpsadre" impossible / retarde" echo $tpsiptest" ne repond pas" cp /tmp/ficmail /etc/tps.mail$jourlog fi # #----------------------- # Copie du mail en texte #----------------------- tpstexte=`/bin/get_key_value /etc/tps.conf tps-texte` if test "$tpstexte" = "oui" then tpstexte=`/bin/get_key_value /etc/tps.conf tps-dossier`"/tps-"`hostname`".txt" echo " Copie du mail => "$tpstexte cat /tmp/ficmail | tail +10 > $tpstexte else tpstexte=`/bin/get_key_value /etc/tps.conf tps-dossier`"/tps-"`hostname` rm -f $tpstexte.log $tpstexte.txt fi #---------- # Nettoyage #---------- rm -f /tmp/ficmail /tmp/tps* #---------------------------------------- # Initialisation des donnees temperatures # et mise a jour de la date courante. #---------------------------------------- if test "$jourlog" != "$jour" then echo "Mise à jour des releves" cat /etc/tps.conf | sed -e 's/tps-jour=".*"/tps-jour="'$jour'"/' > /tmp/tps.conf mv /tmp/tps.conf /etc > /etc/tps.log fi fi fi #================================ # On efface le fichier de blocage #================================ rm -f /tmp/tps-pid # #============================================= # Fin du script 'tps' version du 29 Avril 2007 # par Fred. #=============================================