Files

20 lines
531 B
Bash
Raw Permalink Normal View History

2025-03-24 21:28:20 +00:00
#!/bin/bash
# read from STDIN, lines coming from rsyslog files. Pass to STDOUT any line with timestamp younger than 10 mins
MODE=$1 # supported: <null> or "gitea"
NOW=$(date +"%s")
while read -r LINE; do
if [[ ${MODE} == 'gitea' ]]; then
D="${LINE:0:10}"
D=$( echo $D | awk -F/ '{print $2 "/" $3 "/" $1}')
DT="${D} ${LINE:11:8}"
else
DT=${LINE:0:15}
fi
DT=$(date --date="${DT}" +"%s")
(( SECS = NOW - DT ))
if [[ ${SECS} -lt 601 ]] ; then
echo "$LINE"
fi
done