This repository has been archived on 2023-01-08. You can view files and clone it, but cannot push or open issues or pull requests.
ptrcports/logwrap/logwrap
2022-07-06 15:12:29 +02:00

26 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