refactor tail invokation into logtail.sh

This commit is contained in:
Girish Ramakrishnan
2023-03-27 10:38:09 +02:00
parent 456da972e9
commit 603f92251e
7 changed files with 80 additions and 85 deletions

20
src/scripts/logtail.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/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
exec tail ${follow} --lines=${lines} "$@"