Sometimes, we are searching for a single keyword in log file like, /var/log/ltm or gtm which is very difficult when the number of lines are large and reading logs line by line is not feasible.
In such situation, this code will help a lot and the result will be fast and 100% accurate.
How to use this snippet:
At line number 11, give the path of the file from which you want a keyword to be filtered.
It is starting from "cat".
In the same line, after "egrep -i" add the desired keyword with | symbol.
Your code is ready. If really some critical or positive result will be there it will be shown in RED color.
You can change (reduce or increase) the number in last third line.
#The file name is "check_down_error.sh" which is located in the /opt
#Add the filters you want to search in the log file.
cat /var/log/ltm | egrep -i 'down|DOWN|err|crit|error' > /opt/$latest
if [ ! -s $latest ]
echo -e "\033[7mNo error or Down Message has been found!!\033[0m"
echo -e "\033[7m\033[31mPlease check some ERROR or DOWN Message is there!!\033[0m\033[0m"
echo "Please press any key to See Error logs"
tail -n 30 /opt/$latest
rm -f /opt/$latest