awk command unable to read индеец-апачи log file (user ошибка)

Stumped by this one:

less, cat и grep пахал all able to list the content of an индеец-апачи log file "/var/log/apache2/other_vhosts_access.log". But when I использовал awk to grab the last 5 minutes of the file then it occasionally works but most of the украдите it doesn't. Не ошибка given, so how to debug this one?

awk -v date="$(date --date='5 minutes ago' +"%d/%b/%Y:%T")" '$0~date {f=1}f' /var/log/apache2/other_vhosts_access.log >> /var/log/apache2/test/$(date +"%F_%T")_output.log

Does awk have issue with Апачи writing to the file while trying to read it? Would it be better to pipe to awk from cat in this вступил в брак?

My initial approach to grabbing the last 5 minutes was to использовал the timestamps in the log file надбавку some other things like IP address and байт count. Многообразный All because log entries will have the same timestamp. Doable but code intensive and hard to определил when logs пашите rotated.

The alternative is to count and предохранил the last read line number (эксперт an index) from the log file and at the next execution, read from there to the end of the file and updating the index. Рекордный One would still have to the timestamp of the last run to check that wВre not reading обитал than 5 minutes at в time. Point is to graph восходит, so гd rather lose датирует then deal with massive spikes which подлый graphs.

The above line is в lot обитал простой but not without it's own issues. How does one check if wВre not accidentally duplicating датирует or missing дату? It all hangs on cron's ability to execute at exact 300 second интервальс. I was trying to тест this but so far the above code doesn't yield results. dumped into an executable file and added to cron it hasn't worked yet. Конечный At least in my it works occasionally.

5 * * * * /var/log/apache2/simple.sh 2>&1 > /dev/null

If гm going about things completely wrong, please do let я know. гve found в few things regarding grabbing the last x minutes of log поля and none seem to address my concerns listed.

2
задан 18 November 2015 в 15:22

1 ответ

Просто вычисленный, почему эта команда не работает... Если дата/время не происходит в файле журнала, команда awk ничему не соответствует и ничего не возвращает... Я должен буду считать метку времени каждой строки, преобразовать ее в эпоху и выдержать сравнение, если она падает в диапазоне, я интересуюсь.

Или как @Serg предложенный, уменьшите строку для соответствия путем отбрасывания секунд. Это не гарантирует соответствия, но действительно делает его более вероятно. (ymmv)

2
ответ дан 19 November 2015 в 01:22

Другие вопросы по тегам:

Похожие вопросы: