<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kerry D. Wong &#187; Server Log</title>
	<atom:link href="http://www.kerrywong.com/tag/server-log/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kerrywong.com</link>
	<description></description>
	<lastBuildDate>Fri, 03 Sep 2010 00:51:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Parsing Apache Server Log for Unique IPs</title>
		<link>http://www.kerrywong.com/2009/02/01/parsing-apache-server-log-for-unique-ips/</link>
		<comments>http://www.kerrywong.com/2009/02/01/parsing-apache-server-log-for-unique-ips/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 16:41:01 +0000</pubDate>
		<dc:creator>kwong</dc:creator>
				<category><![CDATA[Linux/BSD]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Server Log]]></category>
		<category><![CDATA[Unique IP]]></category>

		<guid isPermaLink="false">http://www.kerrywong.com/?p=531</guid>
		<description><![CDATA[I created this short Perl script to tally the number of unique IPs from the Apache server log. Since by default, the logrotate daemon compresses Apache logs, we need to disable the compression option for the Apache log configuration. In Ubuntu, this setting can be changed in /etc/logrotate.d/apache2. To disable compression, just comment out the [...]]]></description>
			<content:encoded><![CDATA[<p>I created this short Perl script to tally the number of unique IPs from the Apache server log.<span id="more-531"></span> Since by default, the logrotate daemon compresses Apache logs, we need to disable the compression option for the Apache log configuration. In Ubuntu, this setting can be changed in /etc/logrotate.d/apache2. To disable compression, just comment out the following lines:</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #compress<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #delaycompress</p>
<p>The Perl script is quite straight forward: it basically builds a hash table and use the IP address as the key:</p>
<div>#!/usr/bin/perl</div>
<div>
$apacheLogDir = &quot;/var/log/apache2&quot;;</div>
<div>
opendir(DIR, $apacheLogDir);</div>
<div>@files = grep(/^access/, readdir(DIR));</div>
<div>closedir(DIR);</div>
<div>
%hashTable=();</div>
<div>$uniqueIP = 0;</div>
<div>foreach $file (@files) {</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; open FILE, &quot;$apacheLogDir&quot; . &quot;/&quot; . &quot;$file&quot; or die $!;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @lines = &lt;FILE&gt;;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach $line (@lines) {</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @IP = split(/\s+/, $line);</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (exists($hashTable{$IP[0]})) {</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $hashTable{$IP[0]}++;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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sp;&nbsp;&nbsp;&nbsp;&nbsp; close(FILE);</div>
<div>}</div>
<div>
print &quot;Total unique IPs: $uniqueIP.\n&quot;;</div>
<p>&nbsp;</p>
<p>The two lines commented out:</p>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #$resolved = qx{resolveip $IP[0]};<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #print &quot;$resolved&quot;;</div>
<p>can be used to identify the domain name the IP is associated with. Since reverse DNS lookup is a rather slow process, it will take a long time to resolve all the IPs. I may change it to use multiple threads to speed up the DNS lookup in the further.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kerrywong.com/2009/02/01/parsing-apache-server-log-for-unique-ips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache Log Rotation on Ubuntu Server</title>
		<link>http://www.kerrywong.com/2007/10/03/apache-log-rotation-on-ubuntu-server/</link>
		<comments>http://www.kerrywong.com/2007/10/03/apache-log-rotation-on-ubuntu-server/#comments</comments>
		<pubDate>Thu, 04 Oct 2007 01:57:50 +0000</pubDate>
		<dc:creator>kwong</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Server Log]]></category>

		<guid isPermaLink="false">http://www.kerrywong.com/2007/10/03/apache-log-rotation-on-ubuntu-server/</guid>
		<description><![CDATA[Interestingly, the log rotation utility rotatelogs which came with Apache does not work with Ubuntu 7.04 installation. At least not when the Apache is installed via apt-get. By default, Ubuntu server utilizes logrotate not rotatelogs to rotate all its server logs. Appache access and error logs are rotated on a weekly basis when first installed. [...]]]></description>
			<content:encoded><![CDATA[<p>Interestingly, the log rotation utility <a href="http://httpd.apache.org/docs/2.0/programs/rotatelogs.html">rotatelogs</a> which came with Apache does not work with Ubuntu 7.04 installation. At least not when the Apache is installed via apt-get.<span id="more-225"></span></p>
<p>By default, Ubuntu server utilizes logrotate not rotatelogs to rotate all its server logs. Appache access and error logs are rotated on a weekly basis when first installed. To change the log rotation frequency, you will need to change the following file:&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp; /etc/logrotate.d/apache</p>
<p>The main difference between logrotate and rotatelogs is that logrotate is triggered by a cron job whereas rotatelogs runs in the background as a daemon. In Ubuntu, cron jobs are neatly organized into&nbsp; cron.hourly, cron.daily, cron.weekly and cron.monthly folders. This makes creating ad-hoc cron jobs a very easy task.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kerrywong.com/2007/10/03/apache-log-rotation-on-ubuntu-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
