Skip to content

Instantly share code, notes, and snippets.

@morbeo
Last active November 11, 2021 11:31
Show Gist options
  • Save morbeo/26de548bb6be7bff407e689002236645 to your computer and use it in GitHub Desktop.
Save morbeo/26de548bb6be7bff407e689002236645 to your computer and use it in GitHub Desktop.
tailsince [N minutes] <file> [file..]
#!/usr/bin/env bash
period=$1
shift
for file in $@; do
timeshift=$(date -d"-${period} minutes" +%s);
while read -u3 date time line; do
epoch_timestamp=$(date -d"${date} ${time}" +%s);
if [[ ${timeshift} -lt ${epoch_timestamp} ]]; then
echo "${date} ${time} ${line}";
else
break;
fi;
done 3< <(tac ${file}) | tac
shift
if [[ -n $1 ]]; then echo -- "----- $1 -----"; fi
done
@morbeo
Copy link
Author

morbeo commented Nov 11, 2021

Currently with perp log format

2021-11-11 08:24:50.490544 nginx: ok
^--$date-^ ^-----$time---^ ^-$line->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment