566 tutoriels disponibles
Chercher un tutoriel
Bienvenue
sur Shareannonce
 
Alert by mail load server cpu high
Ecrit par: Shareannonce
Date création:  11-03-2020
Nombre de vues:  1349
Catégorie:  informatique > linux
Note: 
 
   Tutoriel N° 2e5

Alert by mail if your load server cpu high


This script need a web server with php


1/ Create the shell script to execute with cron


nano send_alert.sh

#!/bin/sh

load=$(cat /proc/loadavg | awk '{print $1}');
echo $load;

if [ "`echo "${load} > 2.0" | bc`" -eq 1 ]; then
echo "load > 2"

# use your php path (maybe /usr/bin/php7.2)
# use the command [whereis php] to find your php path
/usr/bin/phpX.Y -q mail.php;
else
echo "load < 2"
fi




2/ Add in Cron daemon your shell script to execute all the 10 minutes


crontab -e

*/10 * * * * /bin/bash /root/send_alert.sh


mail.php


<?php

#send you an email with $load[0] variable
#the php variable $load[0] contains the value of your cpu load

$load = sys_getloadavg();
echo $load[0];

?>





 
 
   Autres tutoriels de la même catégorie >
 
ShareAnnonce version 2.0 Tous droits reserves. | Condition d'utilisation | Contact