Article 5RSY1 Display Last 5 Minutes of Log file Only

Display Last 5 Minutes of Log file Only

by
LinuxRSA
from LinuxQuestions.org on (#5RSY1)
Hi All

I have scripted the below, it checks for HTTP Codes within the NGINX logs.

This is the script:

#!/bin/bash
FILE=/var/log/nginx/access.log
if cat /var/log/nginx/access.log | awk '{print $9}' | grep '400\|401\|403\|404\|409\|500\|501\|502\|503\|504'; then
echo "Nginx Issues"
else
echo "Nginx Healthy"
fi

This is the output:

server:~$ vi testngnix.sh
server:~$
server:~$ cat testngnix.sh
#!/bin/bash
FILE=/var/log/nginx/access.log
if cat /var/log/nginx/access.log | awk '{print $9}' | grep '400\|401\|403\|404\|409\|500\|501\|502\|503\|504'; then
echo "Nginx Issues"
else
echo "Nginx Healthy"
fi
server:~$
server:~$ ./testngnix.sh
502
502
502
502
502
502
502
502
Nginx Issues
server:~$

The challenge I'm having is this script displays the Entire file.

I wish to display the Last 5 minutes of the /var/log/nginx/access.log only.

How can this be achieved ?

Thankslatest?d=yIl2AUoC8zA latest?i=ASw4S2vamyk:ayZDJJdBxWg:F7zBnMy latest?i=ASw4S2vamyk:ayZDJJdBxWg:V_sGLiP latest?d=qj6IDK7rITs latest?i=ASw4S2vamyk:ayZDJJdBxWg:gIN9vFw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments