I need to get the logs of the last n min or n hrs from any log file. I searched and executed many commands but none of them not working. If there is any specific command rather than script it would be perfect. my time format for Nginx is “2022/01/05 11:47:41”
I tried below commands
awk -v bt=$(date "+%s" -d "30 minutes ago") '$1 > bt {printf("%s|%s|%s\n", strftime("%F %T",$1), $3, $7)} ' /var/log/nginx/access.log
sed -n "/^$(date --date="60 minutes ago" "+%d/%b/%Y:%H:%M")/,\$p" /var/log/nginx/access.log
grep -E (date -d -15minutes "+%Y/%m/%d %H:%M"|date -d "+%Y/%m/%d %H:%M")
and many commands like above.