Files
request-tracker/suse.de-request-tracker.cron.weekly

88 lines
2.2 KiB
Bash

#!/bin/bash
#
# $Id$
#
PATH=/bin:/usr/bin
DISTCONFIG="/etc/sysconfig/request-tracker"
##################################################
# Default/Fallback values
# Don't change them here! Use $DISCONFIG instead
##################################################
DEBUG='no'
EMAIL='root@localhost'
HOST=$(hostname -s 2>/dev/null)
LOGFILE='__RT_LOGDIR__/cronjobs-request-tracker.log'
LOGNAME='cron.weekly'
MAILX='/usr/bin/mail'
##################################################
umask 027
unset LANG;
function cleanup_and_exit(){
local exitcode="$1"
exit $exitcode
}
function LOG(){
local MESSAGE="$1"
local LOG_DATE=$(date "+%b %d %H:%M:%S")
if [ -z "$LOGFILE" ]; then
echo "ERROR: LOGFILE is not defined" | $MAILX -s "[$LOGNAME] error on $FQHOSTNAME" $EMAIL
cleanup_and_exit 1
fi
if [ ! -d "$LOGDIR" ]; then
mkdir -p "$LOGDIR" || exit 1
echo "$LOG_DATE $HOST $LOGNAME[$$]: function LOG created $LOGDIR" > "$LOGFILE"
fi
echo "$LOG_DATE $HOST $LOGNAME[$$]: $MESSAGE" >> $LOGFILE || DEBUG="yes"
if [ "$DEBUG" = "yes" ]; then
echo "DEBUG: $MESSAGE"
fi
}
function print_help(){
echo "Usage: $(basename $0) [-c <configfile>]"
echo
echo " -d : turn debug output on"
echo " -f : force execution"
echo " -h : print this message"
echo " -c <configfile> : use the given config file instead of $DISTCONFIG"
echo
exit 0
}
trap cleanup_and_exit 0 1 2 3 7 13 15
while getopts 'fhc:d' OPTION ; do
case $OPTION in
h) print_help
;;
c) DISTCONFIG="$OPTARG"
;;
d) DEBUG='yes'
;;
f) RUN_EMAIL_DIGEST_WEEKLY='yes'
;;
esac
done
shift $(( OPTIND - 1 ))
# source our config
if [ -f "$DISTCONFIG" ]; then
. "$DISTCONFIG"
LOGDIR=$(dirname "$LOGFILE")
else
echo "$DISTCONFIG not found - using defaults" >&2
LOGDIR=$(dirname "$LOGFILE")
LOG "$DISTCONFIG not found - using defaults"
fi
case "$RUN_EMAIL_DIGEST_WEEKLY" in
[Yy][Ee][Ss])
LOG "Running weekly email digest"
__RT_SBINDIR__/rt-email-digest -m weekly
;;
esac