25 lines
375 B
Bash
25 lines
375 B
Bash
#!/bin/sh
|
|
|
|
usage() {
|
|
echo "usage: logwrap [-n NAME] PROGRAM"
|
|
exit 1
|
|
}
|
|
|
|
[ $# = 0 ] && usage
|
|
|
|
name="$1"
|
|
while getopts "n:" opt; do
|
|
case $opt in
|
|
'n') name="$OPTARG" ;;
|
|
*) echo "unknown option: $opt"; usage ;;
|
|
esac
|
|
done
|
|
shift $(( $OPTIND - 1 ))
|
|
|
|
dir=/var/log
|
|
if [ "$(id -u)" != 0 ]; then
|
|
dir="$HOME"/.local/var/log
|
|
fi
|
|
mkdir -p "$dir"
|
|
|
|
exec "$@" >> "$dir/$name.log" 2>&1
|