|
List Info
Thread: Digest Number 1261
|
|
| Digest Number 1261 |
  United States |
2007-09-21 08:20:10 |
|
Messages In This Digest (2
Messages)
Messages
- 1a.
-
Posted by: "Marc Muehlfeld" Marc.Muehlfeld medizinische-genetik.de?Subject= Re%3A%20Modifications%20to%20amdump">
Marc.Muehlfeld medizinische-genetik.de
Thu Sep 20, 2007 1:33 pm (PST)
Hi,
I tried to find a better solution than my last one to improve errorhandling in
amdump.
I modified the script and now it writes the exit codes on failures together
with a human readable message to stdout (some parts are redirected to the
logfile). Also an eMail is send to the configured mailto address (just not,
when I can't read the config, then it's just stdout).
In the later part of the script, commands that fail (e. g. planner,
driver,...) all appearing errors are collected and mailed together in the end.
Also it's printed to stdout/logfile.
I build this new way on a new function "ExitHandler" inside the script.
I just tried this script on linux using bash. I hope I used no bash-only
conditions, so it is platform independent. But it would be nice if someone
could try this on different shells/platformsm, too.
Please let me know your suggestions, improvement suggestions, bugs,...
Regards
Marc
----------
#!/bin/sh
#
# Amanda, The Advanced Maryland Automatic Network Disk Archiver
# Copyright (c) 1991-1998 University of Maryland at College Park
# All Rights Reserved.
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of U.M. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. U.M. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
# BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#
# Author: Marc Muehlfeld, Germany
# http://marc-muehlfeld.de
#
#
# Based on the script amdump from James da Silva, Systems Design and Analysis Group
# Computer Science Department
# University of Maryland at College Park
#
#
# amdump: Manage running one night's Amanda dump run.
#
prefix= prefix
exec_prefix= exec_prefix
sbindir= sbindir
libexecdir= libexecdir
confdir= CONFIG_DIR
PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb
export PATH
# Use version suffixes
USE_VERSION_SUFFIXES=" USE_VERSION_SUFFIXES "
if test "$USE_VERSION_SUFFIXES" = "yes"; then
SUF="- VERSION "
else
SUF=
fi
# Check if no arguments were given.
# We exit here without email, because without config, we can't get the mailto.
if [ $# -lt 1 ] ; then
echo "Usage: amdump config [host [disk...]...]" 1>&2
exit 1
fi
# Check if the configuration directory exists
# We exit here without email, because without existing config, we can't get
# the mailto.
conf=$1
if [ ! -d $confdir/$conf ] ; then
echo "amdump$SUF: could not find directory $confdir/$conf" 1>&2
exit 1
fi
shift
# Check if mail programm is available
MAILER=" MAILER "
if [ ! -x "$MAILER" ] ; then
echo "Mailprogram for reports and errors is missing or not executable." 1>&2
exit 1
else
# Get mailto address for current configuration or quit
MAILTO="`amgetconf$SUF $conf mailto`" 1>&2
if [ $? -ne 0 ] ; then
echo "Can't read amanda.conf. Exiting."
exit 1
fi
fi
# Function for exit handling.
# Usage: ExitHandler [YES|NO] [Error message text] [Exit code]
function ExitHandler () {
# Get variables
CONTINUE="$1"
ERRMSG="$2"
EXITCODE=$3
# On CONTINUE==NO we quit this script (with printing and mailing
# the error message)
if [ "$CONTINUE" == "NO" ] ; then
echo "$ERRMSG" 1>&2
echo "$ERRMSG" | $MAILER -s "ERROR KDD AMANDA REPORT FOR `date +%B" "%e", "%Y`" "$MAILTO"
exit $EXITCODE
fi
# On CONTINUE==YES we print the error (it could go to the log)
# and collect it for a cummulative error email.
if [ "$CONTINUE" == "YES" ] ; then
echo -e "$ERRMSG (Error code: $EXITCODE)" 1>&2
ERRMSG_ALL="$ERRMSG_ALLn$ERRMSG (Error code: $EXITCODE)"
fi
# If no ERRMSG was given, then we are at the end of the script
if [ -z "$ERRMSG" ] ; then
if [ -z "$ERRMSG_ALL" ] ; then
# If we have no errors collected, just quit.
exit $EXITCODE
else
# If we have some errors, print and mail them,
# then quit.
echo -e "$ERRMSG_ALL" | $MAILER -s "ERROR KDD AMANDA REPORT FOR `date +%B" "%e", "%Y`" "$MAILTO"
exit $EXITCODE
fi
fi
}
# Go to configuration directory
cd $confdir/$conf || ExitHandler NO "Can't switch to configuration directory $conf." $?
# Get logdir out of config
logdir=`amgetconf$SUF $conf logdir "$ "`
[ $? -ne 0 ] && ExitHandler NO "Can't get logdir from amanda.conf." $?
# Get tapecycle out of config
tapecycle=`amgetconf$SUF $conf tapecycle "$ "`
[ $? -ne 0 ] && ExitHandler NO "Can't get tapecycle from amanda.con | |