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

26 lines
375 B
Plaintext
Raw Permalink Normal View History

2022-07-06 13:12:29 +00:00
#!/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