I am checking the log on a server multiple times throughout the day. Each time, I open the log in NotePad++ and search for key words such as "warn" or "error" and then review the error or warning to determine my next course of action. Instead of checking it multiple times a day, is there a way to run a script to check the log for errors or warnings?

closed as unclear what you're asking by Jeff Schaller, dr01, Romeo Ninov, Rui F Ribeiro, RalfFriedl Sep 13 '18 at 16:48

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • would you please provide an example of the log file! and the commands you used – user88036 Sep 13 '18 at 13:58
  • Not clear what you're asking. – 炸鱼薯条德里克 Sep 13 '18 at 14:00
  • Can you just use grep to find lines containing the warning error keywords? If you're using a more complex log format, you need to describe it. Then people can give you a sed or Python based script. – 炸鱼薯条德里克 Sep 13 '18 at 14:14

using CRON or AT you can set up a schedule to run a script or program according to any desired schedule such as at specific times repeated every day or once per week.

Look up linux CRON, and crontab -e

as well as linux AT https://linux.die.net/man/1/at

As for a script or program to be run, that would be up to you to implement. Does not need to be complex, simply do a word search within specific log file, if found then do something.

that something can be send an email saying found, or just create a text file with either "NOT FOUND" or "FOUND {with detail}"

you would want to learn BASH shell scripting.

first thing that comes to mind is in linux grep -l "word_pattern" filename

if the grep command does not find your word pattern within the file, then it returns nothing and that can be used within a BASH shell script as your not found condition.

  • Thank you. That was very helpful. I apologize as I should clarify that my attempt was to use BASH and make it as basic as possible. I was asked if I could write a bash script that would check the log for errors, and return a well-defined error message (if there were errors). Then another team could call that script using one of their other monitoring agents, and alert based on that. I don't know if that helps or makes any sense. – rmille05 Sep 13 '18 at 14:32
  • you were fine with " Instead of checking it multiple times a day, is there a way to run a script to check the log for errors or warnings?". If people are going to be so high strung to flag and down vote questions like this then just close down this Unix section. – ron Sep 13 '18 at 14:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.