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 ?
Thanks
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 ?
Thanks