2007-08-16 20:58:37 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Nico Schottelius
|
|
|
|
# written for Netstream (www.netstream.ch)
|
|
|
|
# Date: Fr 8. Jun 10:30:24 CEST 2007
|
2007-08-20 09:58:31 +00:00
|
|
|
# Call the log-wrapper instead of ccollect.sh and it will create nice logs
|
2007-08-16 20:58:37 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# where to find our configuration and temporary file
|
|
|
|
#
|
|
|
|
CCOLLECT_CONF=${CCOLLECT_CONF:-/etc/ccollect}
|
|
|
|
LOGCONF=$CCOLLECT_CONF/logwrapper
|
|
|
|
|
2007-08-20 09:58:31 +00:00
|
|
|
logdir="${LOGCONF}/destination"
|
|
|
|
CDATE="date +%Y%m%d-%H%M"
|
2007-08-20 15:45:06 +00:00
|
|
|
we="$(basename $0)"
|
2007-08-20 09:58:31 +00:00
|
|
|
pid=$$
|
|
|
|
|
2007-08-24 13:44:00 +00:00
|
|
|
export ccollect_logfile="${logdir}/$(${CDATE}).${pid}"
|
2007-08-20 09:58:31 +00:00
|
|
|
|
|
|
|
# use syslog normally
|
2007-08-20 15:35:37 +00:00
|
|
|
# Also use echo, can be redirected with > /dev/null if someone cares
|
2007-08-20 09:58:31 +00:00
|
|
|
_echo()
|
|
|
|
{
|
2007-08-20 15:45:06 +00:00
|
|
|
string="${we} (${pid}): $@"
|
|
|
|
logger "${string}"
|
|
|
|
echo "${string}"
|
2007-08-20 09:58:31 +00:00
|
|
|
}
|
|
|
|
|
2007-08-16 20:58:37 +00:00
|
|
|
|
2007-08-20 09:58:31 +00:00
|
|
|
# exit on error
|
|
|
|
_exit_err()
|
|
|
|
{
|
2007-08-24 13:44:00 +00:00
|
|
|
_echo "$@" >&2
|
2007-08-20 09:58:31 +00:00
|
|
|
rm -f "${TMP}"
|
|
|
|
exit 1
|
|
|
|
}
|
2007-08-16 20:58:37 +00:00
|
|
|
|
2007-08-20 09:58:31 +00:00
|
|
|
# put everything into that specified file
|
|
|
|
_echo "Starting with arguments: $@"
|
2007-08-24 13:44:00 +00:00
|
|
|
touch "${ccollect_logfile}" || _exit_err "Failed to create ${ccollect_logfile}"
|
2007-08-20 15:45:06 +00:00
|
|
|
|
|
|
|
# First line in the logfile is always the commandline
|
2007-08-24 13:44:00 +00:00
|
|
|
echo ccollect.sh "$@" > "${ccollect_logfile}" 2>&1
|
|
|
|
ccollect.sh "$@" >> "${ccollect_logfile}" 2>&1
|
2007-08-20 15:45:06 +00:00
|
|
|
|
2007-08-20 09:58:31 +00:00
|
|
|
_echo "Finished."
|