S
S
San4es1231232020-11-22 20:57:14
linux
San4es123123, 2020-11-22 20:57:14

How to pick up logs from the server for a certain time?


I need to collect logs for 2019.12.30 and 2019.12.31 between 21:30:00 and
21:39:59 2019/12/apache_2019-12-31.txt >> main.txt , but I can't figure out how to pick it up in a certain time

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Victor Taran, 2020-11-23
@San4es123123

is in 1 click search
https://stackoverflow.com/questions/17238908/how-t...
And so the logic is simple you do

cat  you.log | grep "условие по дате" | grep "ваше условие че вы там ищете" | grep " тут еще условие" > 111.txt

if the latter is not done, then just printanet.
Each previous condition will be transmitted to a new input with this symbol |
, that is, the result of the previous command will be sent to the input of the next equivalent of "AND"
But in real work it is much better to use it,
tail -f | grepsince you, unlike opening the log, look here in realtime mode, it is very convenient for work.
If you have a date range, then
awk is better
https://coderoad.ru/30352664/Grep-%D0%BC%D0%B5%D0%...

D
Dimonchik, 2020-11-22
@dimonchik2013

via grep

A
anikavoi, 2020-11-23
@anikavoi

If you need a specific hour, then yes - grep | zgrep
grep "2019-12-30\s09:" .../2019/12/apache_2019-12-30.txt
But there could still be an ambush with logrotation not necessarily set to 00:00.
We tried several toulouse, but ended up scribbling our own.
We have nginx in syslogd, we wrote datagram reception ourselves, although at first we used logstash, but it turned out that everything is simple there. The daemon listens on the port, accepts datagrams, bites off the header, turns the log line into a json string and shoves it into solr.
Then the self-written web muzzle gives you whatever you want, with selections and sortings ...
... even I wrote this, and was surprised - how difficult it is :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question