<?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>108.bz &#187; MS Exchange</title>
	<atom:link href="http://www.108.bz/posts/tag/ms-exchange/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.108.bz</link>
	<description>Wandering futilities...</description>
	<lastBuildDate>Wed, 08 Sep 2010 13:45:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Counting received emails on MS Exchange</title>
		<link>http://www.108.bz/posts/it/counting-received-emails-on-ms-exchange/</link>
		<comments>http://www.108.bz/posts/it/counting-received-emails-on-ms-exchange/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 13:23:46 +0000</pubDate>
		<dc:creator>Giuliano</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[MS Exchange]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.108.bz/?p=340</guid>
		<description><![CDATA[Today I was asked to count the number of emails received on a given address (more than one), across a given time frame. I ended up using Microsoft&#8217;s Log Parser (the existence of which I discovered thanks to this post). Log Parser let&#8217;s you run SQL queries on a range of differently formatted log files. [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was asked to count the number of emails received on a given address (more than one), across a given time frame. I ended up using Microsoft&#8217;s <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&#038;displaylang=en">Log Parser</a> (the existence of which I discovered thanks to <a href="http://msexchangetips.blogspot.com/2006/09/exchange-exporting-and-querying.html">this</a> post).<br />
Log Parser let&#8217;s you run SQL queries on a range of differently formatted log files. Pretty handy stuff: I&#8217;ll surely find other uses for it.</p>
<p>MS Exchange, when Message Tracking is <a href="http://www.msexchange.org/tutorials/Exchange-2003-Message-Tracking-Logging.html">enabled</a>, generates a bunch of log files into something like a <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">C:\Exchsrvr\SERVERNAME.log\</span> folder. The data we need is tracked there.</p>
<div class="codecolorer-container text blackboard" style="border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">logparser -q -i:w3c -o:tsv -headers OFF &quot;SELECT DISTINCT MSGID, To_Lowercase(Recipient-Address) As dst FROM C:\Exchsrvr\SERVERNAME.log\*.log WHERE dst = 'addr1@domain.com' OR dst = 'addr2@domain.com'&quot; &gt; x.tsv</div></div>
<p>&#8220;-q&#8221; stands for &#8220;quiet&#8221;, &#8220;-i:w3c&#8221; states that the input log(s) are in W3C format, &#8220;-o:tsv&#8221; tells Log Parser to output tab-separated fields, &#8220;-headers OFF&#8221; is self explanatory and then comes the SQL query. I&#8217;m selecting distinct combinations of <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">MSGID</span> and <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">Recipient-Address</span>. Distinct because info about an email message is stored in the log files across multiple lines, keyed by MSGID. A single query is enough to filter all of the addresses we&#8217;re interested in, ORed together. Also notice that in the SQL &#8220;FROM&#8221; clause I used &#8220;*.log&#8221;; you may need to change that to suit your time frame (message tracking logs are switched daily and stored for a configurable amount of days).</p>
<p>Log Parser&#8217;s output, redirected to a file, is then fed to cut/sort/uniq. Remember to change the line termination sequence (&#8220;:set fileformat=unix&#8221;, on vim) if you don&#8217;t have the afore mentioned commands on Windows and move the file to a Unix box.</p>
<p>We use <span style="font-family: Bitstream Vera Sans Mono,Courier New,monospace;">cut</span> (which defaults to tab separated fields) to trash MSGID and just select recipients addresses. These ones get sorted and counted. Last step is a reverse numerical sort. This kind of pipe sequence is a rather common &#8220;idiom&#8221; on Unix: it computes word (record) frequencies in a file.</p>
<div class="codecolorer-container text blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cut -f 2 x.tsv | sort | uniq -c | sort -n -r<br />
&nbsp; &nbsp; 782 addr1@domain.com<br />
&nbsp; &nbsp; 747 addr2@domain.com</div></div>
<p>Phew, no lines of script written for once&#8230; <img src='http://www.108.bz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
 <img src="http://www.108.bz/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=340" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.108.bz/posts/it/counting-received-emails-on-ms-exchange/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
