mirror of https://github.com/tLDP/LDP
30 lines
619 B
Bash
30 lines
619 B
Bash
#!/bin/bash
|
|
# logging-wrapper.sh
|
|
# Generic shell wrapper that performs an operation
|
|
#+ and logs it.
|
|
|
|
DEFAULT_LOGFILE=logfile.txt
|
|
|
|
# Set the following two variables.
|
|
OPERATION=
|
|
# Can be a complex chain of commands,
|
|
#+ for example an awk script or a pipe . . .
|
|
|
|
LOGFILE=
|
|
if [ -z "$LOGFILE" ]
|
|
then # If not set, default to ...
|
|
LOGFILE="$DEFAULT_LOGFILE"
|
|
fi
|
|
|
|
# Command-line arguments, if any, for the operation.
|
|
OPTIONS="$@"
|
|
|
|
|
|
# Log it.
|
|
echo "`date` + `whoami` + $OPERATION "$@"" >> $LOGFILE
|
|
# Now, do it.
|
|
exec $OPERATION "$@"
|
|
|
|
# It's necessary to do the logging before the operation.
|
|
# Why?
|