Files
cloudron-box/src/scripts/logtail.sh
2023-03-27 18:53:47 +02:00

24 lines
591 B
Bash
Executable File

#!/bin/bash
set -eu
args=$(getopt -o "" -l "follow,lines:" -n "$0" -- "$@")
eval set -- "${args}"
follow=""
lines=""
while true; do
case "$1" in
--follow) follow="--follow --retry --quiet"; shift;; # same as -F. to make it work if file doesn't exist, --quiet to not output file headers, which are no logs
--lines) lines="$2"; shift 2;;
--) break;;
*) echo "Unknown option $1"; exit 1;;
esac
done
# first sort the existing log lines
tail --quiet --lines=${lines} -- "$@" | sort -k1 || true # ignore error if files are missing
exec tail ${follow} --lines=0 "$@"