automatisation retour code stauts requête / curl
curl –write-out %{http_code} www.google.fr
curl –write-out %{http_code} –silent –output /dev/null adIPsrv
nano verification_serveur.sh
#!/bin/bash
#definition variable
code_http=$(curl –write-out %{http_code} –silent –output /dev/null adIPsrv)cr
#impression du code pour test
echo $code_http
sudo chmod +x verification_serveur.sh
#!/bin/bash
#definition variable, commander vérification code
code_http=$(curl –write-out %{http_code} –silent –output /dev/null adIPsrv)
#si code différent de 200 alors rediger sortie echo vers fichier, et redémarrer Apache
if [ $code_http -ne 200 ]; then
echo « Problème avec le serveur en le redémarrant $(date +%F\ %T) » >> var/log/script/serveur.log
systemctl restart apache2
fi
su
mkdir /var/log/script/
chmod 770 script
chown anto:anto script
automatisation avec cron
systemctl status cron
crontab -e
*/1 * * * * bash /messcripts/verification_serveur.sh
crontab –l
sudo systemctl stop apache2
sudo systemctl status apache2
autre typre de script:
URL= »localhost »
STATE_WEB_HTTP=$(curl –write-out %{http_code} –silent –output /dev/null http://${URL})
#STATE_WEB_HTTPS=$(curl -k –write-out %{http_code} –silent –output /dev/null https://${URL})
HTTP_OK= »# Service Web HTTP : UP »
HTTP_KO= »# Service Web HTTP : DOWN »
HTTP_AB= »# Service Web HTTP : ???? »
if [ ${STATE_WEB_HTTP} = 200 ]; then
echo « ${HTTP_OK} # »
elif [ ${STATE_WEB_HTTP} = 000 ]; then
echo « ${HTTP_KO} # »
elif [ ${STATE_WEB_HTTP} = 301 ]; then
echo « ${HTTP_AB} # »
else
echo « ${HTTP_KO} # »
fi