SuperX-Kernmodul
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

170 lines
4.3 KiB

#!/bin/bash
#(c) 2004 Meikel Bisping
# Executes the given command in the given path and
# logs to commandname.log
# if anything looking like an error occurs a mail is sent if specified
# if the variable $MASTERLOG is set, appends logging to that master log
# the main script should set $MASTERLOG and write a first line into it
# MASTERLOG="/home/superx/joolap/db/master.log";export MASTERLOG
# echo "Start Test proc " > $MASTERLOG
# Copyright 2004 by memtext.de
# für komplexe Aufrufe kann man vorher eine CMD Variable erstellen
# CMD="DOSQL $MODULE"_install_"$DATABASE_ABBR".sql
# runAndCheck.x $MODULE_PATH "$CMD" EXIT_ON_ERROR NO_ERRORMAIL NO_LOGMAIL "$MODULE installieren"
#Änderungen
#28.5.2005 "FATAL" abfangen DQ
#16.04.05 MAILPROG eingefügt.
#21.07.04DQ Flag-überoprüfung bug $FLAG8 -eq 0 fehlte
#19.7.04 MB prüfen, ob Path um . erweitert werden muss
#13.7.04 MB statt mail -s Umgebungsvar MAILPROG (z.B. mail oder mutt)
#08.7.04 MB bei Fehlern wird auch Stichwort error ausgegeben
#28.4.04 MB Logdateien fangen mit L_ an
#23.4.04 MB auch Permission denied abfangen
function showUsage
{
echo "USAGE: runAndCheck.x path command (EXIT_ON_ERROR|CONT_ON_ERROR) (SEND_ERRORMAIL|NO_ERRORMAIL) (SEND_LOGMAIL|NO_LOGMAIL) [description] "
echo "e.g. runAndCheck.x . test.x EXIT_ON_ERROR NO_ERRORMAIL NO_LOGMAIL ""runtest script"" "
}
CPATH=$1
CMD=$2
EXITWANTED=$3
ERRORMAILWANTED=$4
LOGMAILWANTED=$5
DESCRIPTION=$6
if [ "$MAILPROG" = "" ]
then
MAILPROG="mail"
echo "In SQL_ENV bzw. JOOLAP_ENV muss ein Mailprog definiert werden, z.B: MAILPROG=mail oder MAILPROG=mutt export MAILPROG"
fi;
if [ "$CPATH" = "" -o "$CMD" = "" ]
then
showUsage
exit 1
fi;
if [ "$EXITWANTED" != "EXIT_ON_ERROR" -a "$EXITWANTED" != "CONT_ON_ERROR" ]
then
showUsage
exit 1
fi;
if [ "$ERRORMAILWANTED" != "SEND_ERRORMAIL" -a "$ERRORMAILWANTED" != "NO_ERRORMAIL" ]
then
showUsage
exit 1
fi;
if [ "$LOGMAILWANTED" != "SEND_LOGMAIL" -a "$LOGMAILWANTED" != "NO_LOGMAIL" ]
then
showUsage
exit 1
fi;
if [ "$DESCRIPTION" = "" ]
then
DESCRIPTION="aktion"
fi
#Prüfen ob der PATH erweitert werden muss
case $PATH in
.:*)
;;
*:.)
;;
*:.:*)
;;
*)
export PATH=.:$PATH
;;
esac
CURRPATH=`pwd`
#Dateinamen für Log-Datei ohne Leerzeichen erstellen
#echo $DESCRIPTION.log > replace.tmp
LOG=$CPATH/L_` echo $DESCRIPTION.log | tr " " "_" `
#rm replace.tmp
echo ""> $LOG
#write to masterlog about starting first, necessary if one runAndCheck calls another
if [ "$MASTERLOG" != "" ]
then
echo "--Start $DESCRIPTION am "`date +'%x %X'` >> $MASTERLOG
fi
#writing to log file
echo "-- Start $DESCRIPTION am "`date +'%x %X'`>> $LOG
#execute the command
echo "Aktion $DESCRIPTION "
cd $CPATH
echo $CMD >> $LOG 2>&1
$CMD >> $LOG 2>&1
cd $CURRPATH
echo "-- Ende $DESCRIPTION am "`date +'%x %X'` >> $LOG
#update masterlog
if [ ! "$MASTERLOG" = "" ]
then
#cat $LOG >> $MASTERLOG
# log-datei ab Zeile 3 zu masterlog hinzufügen (--start Aktion und Zeit wurde vorher schon ins Masterlog geschrieben)
sed -n -e '3,$p' $LOG>>$MASTERLOG
fi
#searching for errors
fgrep -s "not found" $LOG
FLAG1=$?
fgrep -i -s "error" $LOG
FLAG2=$?
fgrep -i -s "nicht gefunden" $LOG
FLAG3=$?
fgrep -i -s "Exception" $LOG
FLAG4=$?
fgrep -i -s "Keine Berechtigung" $LOG
FLAG5=$?
fgrep -i -s "Permission denied" $LOG
FLAG6=$?
fgrep -i -s "Cannot open file" $LOG
FLAG7=$?
fgrep -i -s "cannot connect" $LOG
FLAG8=$?
fgrep -i -s "fatal" $LOG
FLAG9=$?
fgrep -i -s "fehler" $LOG
FLAG10=$?
fgrep -i -s "abnormal beendet" $LOG
FLAG11=$?
if [ $FLAG1 -eq 0 -o $FLAG2 -eq 0 -o $FLAG3 -eq 0 -o $FLAG4 -eq 0 -o $FLAG5 -eq 0 -o $FLAG6 -eq 0 -o $FLAG7 -eq 0 -o $FLAG8 -eq 0 -o $FLAG9 -eq 0 -o $FLAG10 -eq 0 -o $FLAG11 -eq 0 ]
then
echo "Es ist ein Fehler aufgetreten (error!)"
echo "Pfad: $CPATH Befehl: $CMD Log-Datei: $LOG"
if [ "$ERRORMAILWANTED" = "SEND_ERRORMAIL" -a "$ERRORMAIL" != "" ]
then
echo "sending errormail TO $ERRORMAIL"
$MAILPROG -s "Fehler $DESCRIPTION" $ERRORMAIL <$LOG
fi
if [ "$EXITWANTED" = "EXIT_ON_ERROR" ]
then
#echo "Exiting..."
exit 1
fi
else
echo " .. OK"
echo "(Keine Probleme aufgefallen in $LOG)"
echo
if [ "$LOGMAILWANTED" = "SEND_LOGMAIL" -a "$LOGMAIL" != "" ]
then
echo "sending logmail to $LOGMAIL"
$MAILPROG -s "$DESCRIPTION OK" $LOGMAIL <$LOG
fi
exit 0
fi