Y
Y
Yaroslav2019-07-27 10:38:12
linux
Yaroslav, 2019-07-27 10:38:12

How to run a script shortly after a line appears in the log file?

A common problem - something does not work, and when the admin gets to the problem - the problem is already gone, everything works, there is nothing to debug. There is something in the logs, but a lot (load average, number of HTTP connections, etc. - no). We must wait for the next time (and hope that we will be able to see everything at once).
Here is a problem that leads to a certain entry in the log. Theoretically, I can do tail -f and quickly read the log (downloaded mail service) and in three days it will appear again and I will immediately see what processes are running, what system load, and other troubleshooting.
Naturally, it would be desirable to automate it somehow. That is, you need some kind of program that you specify 1) which file to follow 2) what to look for (substring, regex) and 3) what to run. And when an entry appears in the log, it will run my script and it will already collect all the necessary information about the system, check everything that needs to be checked.
Is there something like that, or maybe somehow on blue electrical tape can be assembled from the existing one?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
arto, 2019-08-08
@xenon

tail -F log | grep --line-buffered text

D
Dmitry Derepko, 2019-07-27
@xEpozZ

Do normal monitoring, not grep every 2 seconds.
Ronald McDonald , are you normal? And if the log weighs 300mb?
I have been able to use Zabbix so far, but there are other monitoring systems.
Cry

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question