Logwatcher script

Aus crazylinux.de
Version vom 4. Oktober 2010, 09:51 Uhr von Jonathan (Diskussion | Beiträge) (init)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springen Zur Suche springen

found on http://2bits.com/articles/logwatcher-restart-apache-after-a-segmentation-fault.html, see for more scripts...


#!/bin/bash

errLog="/var/log/apache2/error.log"
apacheRestart="/etc/init.d/apache2 restart"
failRegex="exit signal Segmentation fault"
scriptLog="/data/logs/http/`basename $0`.log"

while true; do
echo "`date` (re)starting control loop"
tail --follow=name --retry -n 0 "$errLog" 2>/dev/null | while read logLine; do
if [[ `echo "$logLine" | egrep "$failRegex"` ]]; then
echo "`date` Segfault detected, restarting apache"
$apacheRestart
break
fi
done
sleep 5
done >> "$scriptLog" 2>&1 &