2023-03-27 10:38:09 +02:00
#!/bin/bash
set -eu
2024-02-22 18:08:32 +01:00
# root is required for logPaths to work
if [ [ ${ EUID } -ne 0 ] ] ; then
echo "This script should be run as root." > /dev/stderr
exit 1
fi
2023-12-03 16:10:02 +01:00
if [ [ " ${ 1 :- } " = = "--check" ] ] ; then
echo "OK"
exit 0
fi
2023-03-27 10:38:09 +02:00
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
2023-03-27 11:52:25 +02:00
# first sort the existing log lines
2024-08-10 11:13:07 +02:00
tail --quiet --lines= ${ lines } " $@ " | sort -k1 || true # ignore error if files are missing
2023-03-27 11:52:25 +02:00
2023-03-27 18:53:47 +02:00
exec tail ${ follow } --lines= 0 " $@ "