Случвало ли ви се е да ви се наложи да обедините няколко access файла от Apache. Идеята е да направите статистика на сайта с awstats,webalizer или някои друго приложение но това приложение извлича информацията от един файл. За тази цел трябва да обедими файловете ime.access.log и ime.access.log.1 (или всички логове от ime.access.log*) в един файл ime.access.log.FULL. Това може се направи със едно perl скриптче в пакета awstats. За целта първо трябва да инсталирате awstats (apt-get install awstats) и
cp /usr/share/doc/awstats/examples/logresolvemerge.pl /usr/local/bin за
да копирате logresolvermerge като системна команда.
Но сега всичко е наред докато не решите да стартирате logresolvemerge.pl просто за да разберем, че работи нормално(ще ни изведе help страницата си):
dhs:~# logresolvemerge.pl
-bash: /usr/local/bin/logresolvemerge.pl: /usr/bin/perl^M: bad interpreter: No such file or directory
Тук logresolvemrge се чупи не защото има проблем с perl, а защото в сорса има Windows break lines. за да поправим този "проблем" конвертираме към UNIX break lines със dos2unix което приложение се намира в пакета sysutils. за целта инсталираме sysutils:
apt-get install sysutils
след това конвертираме от Windows break lines към Unix break lines:
dos2unix /usr/local/bin/logresolvemerge.pl /usr/local/bin/logresolvemerge.pl
След това тестово изпълняваmе logresolvemrge.pl за да видим дали работи коректно. Ако работи коретно ще ни изведе следната помощна страница:
----- logresolvemerge 1.2 (build 1.34) (c) Laurent Destailleur -----
logresolvemerge allows you to get one unique output log file, sorted on date,
built from particular sources:
-- It can read several input log files,
-- It can read .gz/.bz2 log files,
-- It can also makes a fast reverse DNS lookup to replace
all IP addresses into host names in resulting log file.
logresolvemerge comes with ABSOLUTELY NO WARRANTY. It's a free software
distributed with a GNU General Public License (See COPYING.txt file).
logresolvemerge is part of AWStats but can be used alone as a log merger
or resolver before using any other log analyzer.
Usage:
logresolvemerge.pl [options] file
logresolvemerge.pl [options] file1 … filen
logresolvemerge.pl [options] *.*
perl logresolvemerge.pl [options] *.* > newfile
Options:
-dnslookup make a reverse DNS lookup on IP adresses
-dnslookup=n same with a n parallel threads instead of serial requests
-dnscache=file make DNS lookup from cache file first before network lookup
-showsteps print on stderr benchmark information every 8192 lines
-addfilenum if used with several files, file number can be added in first
-addfilename if used with several files, file name can be added in first
field of output file. This can be used to add a cluster id
when log files come from several load balanced computers.
This runs logresolvemerge in command line to open one or several
server log files to merge them (sorted on date) and/or to make a reverse
DNS lookup (if asked). The result log file is sent on standard output.
Note: logresolvemerge is not a 'sort' tool to sort one file. It's a
software able to output sorted log records (with a reverse DNS lookup
included or not) even if log records are dispatched in several files.
Each of thoose files must be already independently sorted itself
(but that is the case in all web server log files). So you can use it
for load balanced log files or to group several old log files.
Don't forget that the main goal of logresolvemerge is to send log records to
a log analyzer in a sorted order without merging files on disk (NO NEED
OF DISK SPACE AT ALL) and without loading files into memory (NO NEED
OF MORE MEMORY). Choose of output records is done on the fly.
So logresolvemerge is particularly usefull when you want to output several
and/or large log files in a fast process, with no use of disk or
more memory, and in a chronological order through a pipe (to be used by a log
analyzer).
Note: If input records are not 'exactly' sorted but 'nearly' sorted (this
occurs with heavy servers), this is not a problem, the output will also
be 'nearly' sorted but a few log analyzers (like AWStats) knowns how to deal
with such logs.
WARNING: If log files are old MAC text files (lines ended with CR char), you
can't run this tool on Win or Unix platforms.
WARNING: Because of important memory holes in ActiveState Perl version, use
another Perl interpreter if you need to process large lof files.
Now supports/detects:
Automatic detection of log format
Files can be .gz/.bz2 files if zcat/bzcat tools are available in PATH.
Multithreaded reverse DNS lookup (several parallel requests) with Perl 5.8+.
New versions and FAQ at http://awstats.sourceforge.net
След като установихме, че работи перфектно ;) сега ще обединим двата файла ime.access.log и ime.access.log.1 (или всички логове от ime.access.log*) в един файл ime.access.log.FULL като това става със следната команда:
logresolvemerge.pl /var/log/apache2/ime.access.log.* > /var/log/apache2/ime.access.log.FULL
Ето и един доста по- прост начин за обединяване на логовете в Apache, а именно, чрез cat:
cat /var/log/apache2/access.log.1 /var/log/apache2/access.log > /var/log/apache2/access.log.ALL
Това е всичко. Вече имаме един обединен Дневник както се казва в някои български литератури- Logfile на Apache.
VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]