<?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>Code, Systems Admin, Musings...</title>
	<atom:link href="http://codetwit.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codetwit.com</link>
	<description></description>
	<lastBuildDate>Sun, 04 Sep 2011 21:24:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Learning Python Resources</title>
		<link>http://codetwit.com/coding/2011/09/learning-python-resources/</link>
		<comments>http://codetwit.com/coding/2011/09/learning-python-resources/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 21:10:31 +0000</pubDate>
		<dc:creator>basketcase</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=489</guid>
		<description><![CDATA[I originally posted this on my blog http://www.barrymorrison.com/2011/09/04/learning-python-resources/ but thought it&#8217;d be a good fit over hear as well. These are simply links to Python resources I&#8217;ve collected recently in an effort to tech myself Python. Hopefully others can find it equally valuable. http://code.google.com/edu/languages/google-python-class/index.html http://i.imgur.com/YQafj.png http://code.google.com/appengine/docs/python/gettingstarted/ http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/ http://diveintopython.org/toc/index.html http://codingbat.com/ http://www.lightbird.net/py-by-example/ http://rgruet.free.fr/PQR26/PQR2.6.html http://www.udemy.com/learn-python-the-hard-way/ http://learnpythonthehardway.org/ http://www.swaroopch.com/notes/Python http://www.pythonchallenge.com/ [...]]]></description>
			<content:encoded><![CDATA[<p>I originally posted this on my blog <a title="http://www.barrymorrison.com/2011/09/04/learning-python-resources/" href="http://www.barrymorrison.com/2011/09/04/learning-python-resources/" target="_blank">http://www.barrymorrison.com/2011/09/04/learning-python-resources/</a> but thought it&#8217;d be a good fit over hear as well. These are simply links to Python resources I&#8217;ve collected recently in an effort to tech myself Python. Hopefully others can find it equally valuable.</p>
<p><a title="http://code.google.com/edu/languages/google-python-class/index.html" href="http://code.google.com/edu/languages/google-python-class/index.html" target="_blank">http://code.google.com/edu/languages/google-python-class/index.html</a></p>
<p><a title="http://i.imgur.com/YQafj.png" href="http://i.imgur.com/YQafj.png" target="_blank">http://i.imgur.com/YQafj.png</a></p>
<p><a title="http://code.google.com/appengine/docs/python/gettingstarted/" href="http://code.google.com/appengine/docs/python/gettingstarted/" target="_blank">http://code.google.com/appengine/docs/python/gettingstarted/</a></p>
<p><a title="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/" href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/" target="_blank">http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/</a></p>
<p><a title="http://diveintopython.org/toc/index.html" href="http://diveintopython.org/toc/index.html" target="_blank">http://diveintopython.org/toc/index.html</a></p>
<p><a title="http://codingbat.com/" href="http://codingbat.com/" target="_blank">http://codingbat.com/</a></p>
<p><a title="http://www.lightbird.net/py-by-example/" href="http://www.lightbird.net/py-by-example/" target="_blank">http://www.lightbird.net/py-by-example/</a></p>
<p><a title="http://rgruet.free.fr/PQR26/PQR2.6.html" href="http://rgruet.free.fr/PQR26/PQR2.6.html" target="_blank">http://rgruet.free.fr/PQR26/PQR2.6.html</a></p>
<p><a title="http://www.udemy.com/learn-python-the-hard-way/" href="http://www.udemy.com/learn-python-the-hard-way/" target="_blank">http://www.udemy.com/learn-python-the-hard-way/</a></p>
<p><a title="http://learnpythonthehardway.org/" href="http://learnpythonthehardway.org/" target="_blank">http://learnpythonthehardway.org/</a></p>
<p><a title="http://www.swaroopch.com/notes/Python" href="http://www.swaroopch.com/notes/Python" target="_blank">http://www.swaroopch.com/notes/Python</a></p>
<p><a title="http://www.pythonchallenge.com/" href="http://www.pythonchallenge.com/" target="_blank">http://www.pythonchallenge.com/</a></p>
<p><a title="http://www.youtube.com/user/thenewboston#p/search/0/4Mf0h3HphEA" href="http://www.youtube.com/user/thenewboston#p/search/0/4Mf0h3HphEA" target="_blank">http://www.youtube.com/user/thenewboston#p/search/0/4Mf0h3HphEA</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/coding/2011/09/learning-python-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get Yesterday&#8217;s Date</title>
		<link>http://codetwit.com/coding/2011/08/get-yesterdays-date/</link>
		<comments>http://codetwit.com/coding/2011/08/get-yesterdays-date/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 00:37:53 +0000</pubDate>
		<dc:creator>basketcase</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[yesterday]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=326</guid>
		<description><![CDATA[I was working on a script that parsed log files. The file names were log.mmddyy (log.080811). This was a little bit of a learning experience for me (new to shell scripting). I was working on a Solaris 10 box, but I thought I&#8217;d do all my dev/testing on Ubuntu. Big mistake. Linux was running bash/gnu [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a script that parsed log files.  The file names were log.mmddyy (log.080811).  This was a little bit of a learning experience for me (new to shell scripting).  I was working on a Solaris 10 box, but I thought I&#8217;d do all my dev/testing on Ubuntu.  Big mistake.  Linux was running bash/gnu tools.  Solaris was not.  After I figured out how to do it on Ubuntu, I had to figure out how to do it on Solaris (thanks Scott!), then I did it in Powershell (had done something similar already for another script) and since I&#8217;m teaching myself Python, I wanted to do it in Python. </p>
<p>Are they the &#8220;right&#8221; way to do them?  They work!  Probably not a &#8220;right&#8221; way to do them, as there is always more than one way to do something</p>
<h3>Shell</h3>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="co0">#!/bin/bash</span>
&nbsp;
<span class="re2">os</span>=<span class="sy0">`</span><span class="kw2">uname</span><span class="sy0">`</span>
&nbsp;
<span class="kw1">if</span> <span class="br0">&#91;</span> <span class="re1">$os</span> == <span class="st_h">'Linux'</span> <span class="br0">&#93;</span>;
    <span class="kw1">then</span>
    <span class="re2">yesterday</span>=<span class="sy0">&amp;</span>quot;$<span class="br0">&#40;</span><span class="kw2">date</span> <span class="re5">-d</span> <span class="st_h">'yesterday'</span> +<span class="sy0">%</span>m<span class="sy0">%</span>d<span class="sy0">%</span>y<span class="br0">&#41;</span><span class="sy0">&amp;</span>quot;
    <span class="kw3">echo</span> <span class="re1">$yesterday</span>
<span class="kw1">elif</span> <span class="br0">&#91;</span> <span class="re1">$os</span> == <span class="st_h">'SunOS'</span> <span class="br0">&#93;</span>;
    <span class="kw1">then</span>
    <span class="re2">yesterday</span>=<span class="sy0">`</span><span class="re2">TZ</span>=GMT+<span class="nu0">24</span> <span class="kw2">date</span> +<span class="sy0">%</span>m<span class="sy0">%</span>d<span class="sy0">%</span>y<span class="sy0">`</span>
    <span class="kw3">echo</span> <span class="re1">$yesterday</span>
<span class="kw1">fi</span></pre></div></div></div></div></div></div></div>


<h3>Gnu Date</h3>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="co0">#!/usr/bin/bash</span>
&nbsp;
<span class="co0">## Get Yesterday</span>
<span class="re2">yesterday</span>=<span class="sy0">&amp;</span>quot;$<span class="br0">&#40;</span><span class="kw2">date</span> <span class="re5">-d</span> <span class="st_h">'yesterday'</span> +<span class="sy0">%</span>m<span class="sy0">%</span>d<span class="sy0">%</span>y<span class="br0">&#41;</span><span class="sy0">&amp;</span>quot;</pre></div></div></div></div></div></div></div>


<h3>Powershell</h3>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="powershell"><pre class="de1"><span class="re0">$yesterday</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="kw1">get-date</span> <span class="kw5">-format</span> mmddyy<span class="br0">&#41;</span>.adddays<span class="br0">&#40;</span><span class="sy0">-</span><span class="nu0">1</span><span class="br0">&#41;</span>
<span class="re0">$yesterday</span>.tostring<span class="br0">&#40;</span><span class="st0">'MMddyy'</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>


<h3>Python</h3>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="python"><pre class="de1">&nbsp;
<span class="kw1">import</span> <span class="kw3">datetime</span>
today <span class="sy0">=</span> <span class="kw3">datetime</span>.<span class="kw3">datetime</span>.<span class="me1">today</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
one_day <span class="sy0">=</span> <span class="kw3">datetime</span>.<span class="me1">timedelta</span><span class="br0">&#40;</span>days<span class="sy0">=</span><span class="nu0">1</span><span class="br0">&#41;</span>
yesterday <span class="sy0">=</span> today - one_day
yesterday.<span class="me1">strftime</span><span class="br0">&#40;</span><span class="st0">'%m%d%y'</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>


]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/coding/2011/08/get-yesterdays-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Normalize MAC address with Python</title>
		<link>http://codetwit.com/sysadmin/2011/08/normalize-mac-address-with-python/</link>
		<comments>http://codetwit.com/sysadmin/2011/08/normalize-mac-address-with-python/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 00:32:33 +0000</pubDate>
		<dc:creator>basketcase</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=361</guid>
		<description><![CDATA[In an earlier post, Scott did this in a simple shell script. I was curious if I could do it in Python since I am learning Python. Below is my first attempt. Watch for upcoming updated version. import sys &#160; if not sys.argv&#91;1:&#93;: mac = raw_input &#40;&#34;Enter MAC address\n&#34;&#41; print &#34;Mac is %s\n&#34;; % &#40;mac&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>In an earlier <a href="http://codetwit.com/sysadmin/2011/08/normalize-mac-address-for-dhcp-reservations/" title="Normalize MAC address for DHCP reservations" target="_blank">post</a>, Scott did this in a simple shell script.  I was curious if I could do it in Python since I am learning Python. </p>
<p>Below is my first attempt.  Watch for upcoming updated version.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="python"><pre class="de1"><span class="kw1">import</span> <span class="kw3">sys</span>
&nbsp;
<span class="kw1">if</span> <span class="kw1">not</span> <span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#91;</span><span class="nu0">1</span>:<span class="br0">&#93;</span>:
   mac <span class="sy0">=</span> <span class="kw2">raw_input</span> <span class="br0">&#40;</span><span class="st0">&quot;Enter MAC address<span class="es0">\n</span>&quot;</span><span class="br0">&#41;</span>
   <span class="kw1">print</span> <span class="st0">&quot;Mac is %s<span class="es0">\n</span>&quot;</span><span class="sy0">;</span> % <span class="br0">&#40;</span>mac<span class="br0">&#41;</span>
   <span class="co1">#sys.exit(0)</span>
<span class="kw1">else</span>:
   mac <span class="sy0">=</span> <span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>
   <span class="kw1">print</span> <span class="st0">&quot;Mac is %s<span class="es0">\n</span>&quot;</span> % <span class="br0">&#40;</span>mac<span class="br0">&#41;</span>
&nbsp;
<span class="co1">##I'm checking to see if someone is giving me in the right format</span>
maclen<span class="sy0">=</span><span class="kw2">len</span><span class="br0">&#40;</span>mac<span class="br0">&#41;</span>
<span class="kw1">if</span> maclen <span class="sy0">==</span> <span class="nu0">12</span>:
    <span class="co1">## converting to list, since strings are immuatable</span>
    maclist<span class="sy0">=</span><span class="kw2">list</span><span class="br0">&#40;</span>mac<span class="br0">&#41;</span>
    <span class="co1">## defining positions on list</span>
    positions<span class="sy0">=</span><span class="nu0">2</span><span class="sy0">,</span><span class="nu0">5</span><span class="sy0">,</span><span class="nu0">8</span><span class="sy0">,</span><span class="nu0">11</span><span class="sy0">,</span><span class="nu0">14</span>
&nbsp;
    <span class="kw1">for</span> i <span class="kw1">in</span> positions:
        maclist.<span class="me1">insert</span><span class="br0">&#40;</span>i<span class="sy0">,</span><span class="st0">':'</span><span class="br0">&#41;</span>
    <span class="co1">##joining list at the ','</span>
    newmac<span class="sy0">=</span><span class="st0">&quot;,&quot;</span>.<span class="me1">join</span><span class="br0">&#40;</span>maclist<span class="br0">&#41;</span>
    <span class="co1">## stripping ',' out and converting to lowercase.  </span>
    final12mac<span class="sy0">=</span>newmac.<span class="me1">replace</span><span class="br0">&#40;</span><span class="st0">','</span><span class="sy0">,</span><span class="st0">''</span><span class="br0">&#41;</span>.<span class="me1">lower</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp;
    <span class="kw1">print</span> final12mac
&nbsp;
<span class="co1">##assuming that 17 characters will either have - or : in MAC address    </span>
<span class="kw1">elif</span> maclen <span class="sy0">==</span> <span class="nu0">17</span>:
    <span class="co1">##replacing - with : and converting to lowercase</span>
    mac17final<span class="sy0">=</span>mac.<span class="me1">replace</span><span class="br0">&#40;</span><span class="st0">'-'</span><span class="sy0">,</span><span class="st0">':'</span><span class="br0">&#41;</span>.<span class="me1">lower</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
    <span class="kw1">print</span> mac17final
<span class="kw1">else</span>:
    <span class="co1">## I'm telling them that if it isn't 12 or 17 characters, it has X chars</span>
    <span class="kw1">print</span> <span class="st0">&quot;There are only %s characters&quot;</span> % <span class="br0">&#40;</span>maclen<span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>


]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/sysadmin/2011/08/normalize-mac-address-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interview questions &#8230; Get IP address from Apache Logs</title>
		<link>http://codetwit.com/sysadmin/2011/08/interview-questions-apache-logs/</link>
		<comments>http://codetwit.com/sysadmin/2011/08/interview-questions-apache-logs/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 05:29:44 +0000</pubDate>
		<dc:creator>snyce</dc:creator>
				<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[cat]]></category>
		<category><![CDATA[interview questions]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[uniq]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=418</guid>
		<description><![CDATA[TL;DR Some Apache log processing one liners to get IP addresses from the access and error logs that I have found handy. There may be some log processing questions asked during the course of an interview, so I am going to concentrate on a couple that will get the IP addresses from the apache log [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>TL;DR Some Apache log processing one liners to get IP addresses from the access and error logs that I have found handy.</em></strong></p>
<p>There may be some log processing questions asked during the course of an interview, so I am going to concentrate on a couple that will get the IP addresses from the apache log files. If you do have log processing quesitons I sincerely hope you get to play at a command line, as off the top of the head can be difficult, unless you&#8217;re good at visualizing commands.</p>
<pre>
Q: How would you get the IP address from the access logs?
A: This one is fairly straight forward, I would:
</pre>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="kw2">cat</span> access.log <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st_h">'{print $1}'</span> <span class="sy0">|</span> <span class="kw2">uniq</span></pre></div></div></div></div></div></div></div>


<p>This will output (if you choose not to use uniq you will see multiple of the same ip, I&#8217;ll leave to the discretion of the reader):</p>
<pre>
127.0.0.1
127.0.0.2
127.0.0.3
</pre>
<p>The breakdown is as follows:</p>
<ul>
1. read through the contents of the file (cat access.log)<br />
2. pipe output to awk to print the first field ($1)<br />
3. pipe output to only show unique data (uniq)
</ul>
<p>Another question might be to parse out the IP address from the error.log, while this is a bit more difficult, it is fairly straight forward using readily available system tools.</p>
<pre>
Q: Can you please extract the IP address from the error.log?
A: Here is my solution (Thanks Malcolm!)
</pre>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="kw2">cat</span> error.log <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st_h">'{ if($7 == &quot;[client&quot;) {print $8} }'</span> <span class="sy0">|</span> <span class="kw2">sed</span> <span class="re5">-e</span> <span class="st_h">'s/]$//g'</span> <span class="sy0">|</span> <span class="kw2">uniq</span></pre></div></div></div></div></div></div></div>


<p>The breakdown is as follows, this one is a bit more complex so I will walk through each step of it:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">First part: <span class="kw2">cat</span> error.log - <span class="kw2">read</span> through the log file.
&nbsp;
<span class="br0">&#91;</span>Sun Aug <span class="nu0">14</span> <span class="nu0">13</span>:<span class="nu0">27</span>:<span class="nu0">14</span> <span class="nu0">2011</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>error<span class="br0">&#93;</span> <span class="br0">&#91;</span>client 96.126.120.254<span class="br0">&#93;</span> Invalid method <span class="kw1">in</span> request \x80e\x01\x03\x01
<span class="br0">&#91;</span>Sun Aug <span class="nu0">14</span> <span class="nu0">13</span>:<span class="nu0">27</span>:<span class="nu0">14</span> <span class="nu0">2011</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>error<span class="br0">&#93;</span> <span class="br0">&#91;</span>client 96.126.120.254<span class="br0">&#93;</span> Invalid method <span class="kw1">in</span> request \x80e\x01\x03\x01
<span class="br0">&#91;</span>Sun Aug <span class="nu0">14</span> <span class="nu0">13</span>:<span class="nu0">27</span>:<span class="nu0">14</span> <span class="nu0">2011</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>error<span class="br0">&#93;</span> <span class="br0">&#91;</span>client 96.126.120.254<span class="br0">&#93;</span> Invalid method <span class="kw1">in</span> request \x80e\x01\x03\x01
<span class="br0">&#91;</span>Sun Aug <span class="nu0">14</span> <span class="nu0">13</span>:<span class="nu0">27</span>:<span class="nu0">14</span> <span class="nu0">2011</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>error<span class="br0">&#93;</span> <span class="br0">&#91;</span>client 96.126.120.254<span class="br0">&#93;</span> Invalid method <span class="kw1">in</span> request \x80e\x01\x03\x01
<span class="br0">&#91;</span>Mon Aug <span class="nu0">15</span> <span class="nu0">15</span>:<span class="nu0">16</span>:<span class="nu0">21</span> <span class="nu0">2011</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>error<span class="br0">&#93;</span> <span class="br0">&#91;</span>client 194.72.238.62<span class="br0">&#93;</span> Invalid method <span class="kw1">in</span> request \x16\x03\x01
<span class="br0">&#91;</span>Mon Aug <span class="nu0">15</span> <span class="nu0">15</span>:<span class="nu0">50</span>:<span class="nu0">27</span> <span class="nu0">2011</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>notice<span class="br0">&#93;</span> caught SIGWINCH, shutting down gracefully
<span class="br0">&#91;</span>Mon Aug <span class="nu0">15</span> <span class="nu0">15</span>:<span class="nu0">50</span>:<span class="nu0">37</span> <span class="nu0">2011</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>notice<span class="br0">&#93;</span> mod_python: Creating <span class="nu0">8</span> session mutexes based on <span class="nu0">75</span> max processes and <span class="nu0">0</span> max threads.
<span class="br0">&#91;</span>Mon Aug <span class="nu0">15</span> <span class="nu0">15</span>:<span class="nu0">50</span>:<span class="nu0">37</span> <span class="nu0">2011</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>notice<span class="br0">&#93;</span> mod_python: using mutex_directory <span class="sy0">/</span>tmp 
PHP Warning:  Module <span class="st_h">'gd'</span> already loaded <span class="kw1">in</span> Unknown on line <span class="nu0">0</span>
PHP Warning:  Module <span class="st_h">'mysql'</span> already loaded <span class="kw1">in</span> Unknown on line <span class="nu0">0</span>
PHP Warning:  Module <span class="st_h">'mysqli'</span> already loaded <span class="kw1">in</span> Unknown on line <span class="nu0">0</span>
<span class="br0">&#91;</span>Mon Aug <span class="nu0">15</span> <span class="nu0">15</span>:<span class="nu0">50</span>:<span class="nu0">38</span> <span class="nu0">2011</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>warn<span class="br0">&#93;</span> mod_wsgi: Compiled <span class="kw1">for</span> Python<span class="sy0">/</span>2.5.1.
<span class="br0">&#91;</span>Mon Aug <span class="nu0">15</span> <span class="nu0">15</span>:<span class="nu0">50</span>:<span class="nu0">38</span> <span class="nu0">2011</span><span class="br0">&#93;</span> <span class="br0">&#91;</span>warn<span class="br0">&#93;</span> mod_wsgi: Runtime using Python<span class="sy0">/</span>2.5.2.
&nbsp;
<span class="nu0">2</span>. Second part: <span class="kw2">cat</span> error.log <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st_h">'{ if ($7 == &quot;[client&quot;) {print $8} }'</span> - <span class="kw1">if</span> the 7th field matches client <span class="br0">&#40;</span>this seems to be pretty standard though ymmv<span class="br0">&#41;</span> print out eighth field <span class="br0">&#40;</span><span class="kw2">which</span> should be the IP address, also notice the trailing <span class="st0">&quot;]&quot;</span> character<span class="br0">&#41;</span>.
&nbsp;
96.126.120.254<span class="br0">&#93;</span>
96.126.120.254<span class="br0">&#93;</span>
96.126.120.254<span class="br0">&#93;</span>
96.126.120.254<span class="br0">&#93;</span>
194.72.238.62<span class="br0">&#93;</span>
&nbsp;
<span class="nu0">3</span>. Third Part: <span class="kw2">cat</span> error.log <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st_h">'{ if ($7 == &quot;[client&quot;) {print $8} }'</span> <span class="sy0">|</span> <span class="kw2">sed</span> <span class="re5">-e</span> <span class="st_h">'s/]$//g'</span> - use <span class="kw2">sed</span> to remove the trailing <span class="st0">&quot;]&quot;</span> character.
&nbsp;
96.126.120.254
96.126.120.254
96.126.120.254
96.126.120.254
194.72.238.62
&nbsp;
<span class="nu0">4</span>. Fourth Part: <span class="kw2">cat</span> error.log <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st_h">'{ if ($7 == &quot;[client&quot;) {print $8} }'</span> <span class="sy0">|</span> <span class="kw2">sed</span> <span class="re5">-e</span> <span class="st_h">'s/]$//g'</span> <span class="sy0">|</span> <span class="kw2">uniq</span> - lets output unique ips and not all of them <span class="br0">&#40;</span>multiple matches<span class="br0">&#41;</span>.
&nbsp;
96.126.120.254
194.72.238.62</pre></div></div></div></div></div></div></div>


<p>Addendum:<br />
If you would like you can then add another awk on the end (or pipe to any other command you feel like) for instance. The following pipes the output to the host command:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="br0">&#91;</span>Edit: <span class="kw1">for</span> host might want to specify the <span class="re5">-W</span> <span class="sy0">&lt;</span><span class="kw1">time</span><span class="sy0">&gt;</span> flag just <span class="kw1">in</span> <span class="kw1">case</span>, it could try forever on some unless specified<span class="br0">&#93;</span>
<span class="kw2">cat</span> error.log <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st_h">'{ if ($7 == &quot;[client&quot;) {print $8} }'</span> <span class="sy0">|</span> <span class="kw2">sed</span> <span class="re5">-e</span> <span class="st_h">'s/]$//g'</span> <span class="sy0">|</span> <span class="kw2">uniq</span> <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st_h">'{ print | &quot;host -W 3 &quot; $1 }'</span></pre></div></div></div></div></div></div></div>


<p>I hope this helps, share and enjoy! Thanks for reading!</p>
<p>-Scott.</p>
<p><strong><em>Disclaimer: I make no claims to the viability of the code/script/commands and make no guarantees that it will work on your system, use at your own risk.</em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/sysadmin/2011/08/interview-questions-apache-logs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interview questions &#8230; part one</title>
		<link>http://codetwit.com/sysadmin/2011/08/interview-questions-part-one/</link>
		<comments>http://codetwit.com/sysadmin/2011/08/interview-questions-part-one/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 17:49:12 +0000</pubDate>
		<dc:creator>snyce</dc:creator>
				<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[interview questions]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=278</guid>
		<description><![CDATA[TL;DR I like interview questions, this is completely subjective, name 5 two letter linux commands and what they do. Everyone once in a while I&#8217;ll go looking for good technical interview questions to challenge myself, to see how far I&#8217;ve grown, and it is for me a good way to ground myself and figure out [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>TL;DR</strong></em><br />
<em>I like interview questions, this is completely subjective, name 5 two letter linux commands and what they do.</em></p>
<p>Everyone once in a while I&#8217;ll go looking for good technical interview questions to challenge myself, to see how far I&#8217;ve grown, and it is for me a good way to ground myself and figure out how far I need to grow. I tend to be of the mindset that it&#8217;s good to keep the questions somewhat open ended, I think a lot of what shows a persons aptitude is their ability to reason out answers to difficult questions, not whether or not they remember what the theoretical throughput of 8Gig Fibre Channel (about 1600MBps if I remember correctly, but I digress). So what I am going to do is go out find / make up what I think are good interview questions (or ones that just strike my fancy, and why yes this is completely subjective thanks for pointing that out) and answer them from my own experience. I can&#8217;t say that my solutions will be the *right* way to do it, but hopefully give the correct results, but I make no promises.</p>
<p>So for the first round I am going to echo a question that I got as an interview question and really liked, and maybe take it a bit further:</p>
<pre>
Q: Can you name five two letter Linux commands?
A: Yes I can (and did).
</pre>
<p>Now this is a good question for those starting out to gauge how far they have gone into the system admin side of things, stuff that you can&#8217;t necessarily (or as quickly) do from just the gui. So the thing that I thought of to make this more interesting is:</p>
<pre>
Q: Can you name five two letter linux commands, and what they do? Give an example of each two letter command you give.
</pre>
<p>I personally think this is interesting because not only does it cause some of the more senior people to have to think (muscle memory is a helluva drug), but it also will show a good basic understanding of what is going with the commands that are being used. In all honesty I don&#8217;t remember all of them, and I don&#8217;t remember ever single command line switch for them, that is why man pages exist.</p>
<p>Share and enjoy!</p>
<p>-Scott.</p>
]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/sysadmin/2011/08/interview-questions-part-one/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Normalize MAC address for DHCP reservations</title>
		<link>http://codetwit.com/sysadmin/2011/08/normalize-mac-address-for-dhcp-reservations/</link>
		<comments>http://codetwit.com/sysadmin/2011/08/normalize-mac-address-for-dhcp-reservations/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 21:19:23 +0000</pubDate>
		<dc:creator>snyce</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[DHCP]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=341</guid>
		<description><![CDATA[So part of what I am doing at my current job is helping one of the Unix admins with DNS and DHCP. For the DHCP portion to setup the reservations we need the MAC addy in a certain format, of which the people requesting never seem to get consistently right, so I wrote a small [...]]]></description>
			<content:encoded><![CDATA[<p>So part of what I am doing at my current job is helping one of the Unix admins with DNS and DHCP. For the DHCP portion to setup the reservations we need the MAC addy in a certain format, of which the people requesting never seem to get consistently right, so I wrote a small shell script (it&#8217;s still rough) that will normalize the MAC address for what we need (colon separated, alpha characters lower case).<br />
<br />[Edit: the below only works on FreeBSD and Linux, for Solaris swap the awk '{print tolower($0)}' with tr '[:upper:]&#8216; &#8216;[:lower:]&#8216; <- or you could just do that for all of them as well).</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="co0">#!/usr/bin/env sh</span>
&nbsp;
<span class="re2">mac</span>=<span class="st0">&quot;$1&quot;</span>
&nbsp;
<span class="co0">#check to see if input is empty</span>
<span class="kw1">if</span> <span class="br0">&#91;</span> <span class="sy0">!</span> <span class="re5">-n</span> <span class="st0">&quot;<span class="es2">$mac</span>&quot;</span> <span class="br0">&#93;</span>
    <span class="kw1">then</span>
        <span class="kw3">echo</span> <span class="st0">&quot;Please enter a MAC address.&quot;</span>
        <span class="kw3">exit</span>
<span class="kw1">else</span> 
    <span class="co0"># echo the input, strip out dot(.), strip out colon(:), strip out dash(-)</span>
    <span class="co0"># add colon(:) every two chars, remove last colon(:)</span>
    <span class="co0"># awk to lowercase characters [EDIT: updated the sed for . seps and escape]</span>
    <span class="kw3">echo</span> <span class="re1">$mac</span> <span class="sy0">|</span> <span class="kw2">sed</span> <span class="re5">-e</span> <span class="st_h">'s/\.//g'</span> <span class="re5">-e</span> <span class="st_h">'s/\://g'</span> <span class="re5">-e</span> <span class="st_h">'s/\-//g'</span> <span class="re5">-e</span> <span class="st_h">'s/../&amp;:/g'</span> <span class="re5">-e</span> <span class="st_h">'s/:$//g'</span> \
<span class="sy0">|</span> <span class="kw2">awk</span> <span class="st_h">'{print tolower($0)}'</span>
<span class="kw1">fi</span></pre></div></div></div></div></div></div></div>


<p>Some of the standard formats we see are:<br />
1A:BC:35:57:33:08<br />
1A-BC-35-57:33:08<br />
1ABC35573308<br />
1abc35573308<br />
1a.bc.35.57.33.08<br />
1A.BC.35.57.33.08</p>
<p>The script will take all of these and make them look like: 1a:bc:35:57:33:08.</p>
<p>Here is the breakdown for those that are curious:<br />
1. if [ ! -n "$mac" ] checks to make sure first input variable is not empty.<br />
2. echo $mac outputs the first argument (does not do any input validation)<br />
3. The sed is in five parts:</p>
<ul>
<pre>
[Edited to escape the sequences, just in case they should have special meaning]
    a. 's/\.//g' strips out the period should it be in that format
    b. 's/\://g' strips out the colons should they be there (to avoid extra colons)
    c. 's/\-//g' strips out the dashes should they be in that format
    d. 's/../&#038;:/g' every two characters append a colon
    e. 's/:$//g' remove the last trailing colon
</pre>
</ul>
<p>4. awk &#8216;{print tolower($0)}&#8217; make all of the upper case alpha chars lower case to match our format needs.<br />
4a. tr &#8216;[:upper:]&#8216; &#8216;[:lower:]&#8216; for Solaris (yes I know tr &#8216;[A-Z]&#8216; &#8216;[a-z]&#8216; will work as well, but this is easier to read IMHO)</p>
<p>This will work on a file full of MAC addresses, just throw it in a for loop (this is if you name the file macnorm.sh):</p>
<pre>for i in `cat filename`; do ./macnorm.sh $i; done</pre>
<p>Again it is important to realize that there is no checking of the input, so if you did it over /etc/passwd it would add a colon (:) every two characters. Hope this helps.</p>
<p>-Scott.</p>
]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/sysadmin/2011/08/normalize-mac-address-for-dhcp-reservations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FizzBuzz</title>
		<link>http://codetwit.com/coding/2011/08/fizzbuzz/</link>
		<comments>http://codetwit.com/coding/2011/08/fizzbuzz/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 05:11:51 +0000</pubDate>
		<dc:creator>snyce</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=333</guid>
		<description><![CDATA[Because someone I follow on twitter mentioned it (I had read this article before), I did the fizzbuzz in python (quite a while ago), though as someone pointed out not very pythonically, here&#8217;s my entry (non-pythonic python): I&#8217;ll maybe work on making it more pythonic later. #!/usr/bin/env python &#160; i = 100 count = 0 [...]]]></description>
			<content:encoded><![CDATA[<p>Because someone <a href="http://www.hollenback.net/index.php/FizzBuzz">I follow on twitter</a> mentioned it (I had read <a href="http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/">this article before</a>), I did the fizzbuzz in python (quite a while ago), though as someone pointed out not very pythonically, here&#8217;s my entry (non-pythonic python):</p>
<p>I&#8217;ll maybe work on making it more pythonic later.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="python"><pre class="de1"><span class="co1">#!/usr/bin/env python</span>
&nbsp;
i <span class="sy0">=</span> <span class="nu0">100</span>
count <span class="sy0">=</span> <span class="nu0">0</span>
<span class="kw1">while</span> <span class="br0">&#40;</span>count <span class="sy0">&lt;</span> i<span class="br0">&#41;</span>:
    <span class="kw1">if</span> <span class="br0">&#40;</span>count % <span class="nu0">3</span> <span class="sy0">==</span> <span class="nu0">0</span> <span class="kw1">and</span> count % <span class="nu0">5</span> <span class="sy0">==</span> <span class="nu0">0</span><span class="br0">&#41;</span>:
        <span class="kw1">print</span> <span class="st0">&quot;FizzBuzz: %d&quot;</span> % <span class="br0">&#40;</span>count<span class="br0">&#41;</span>
    <span class="kw1">elif</span> <span class="br0">&#40;</span>count % <span class="nu0">5</span> <span class="sy0">==</span> <span class="nu0">0</span> <span class="kw1">and</span> count &amp;gt<span class="sy0">;</span> <span class="nu0">0</span><span class="br0">&#41;</span>:
        <span class="kw1">print</span> <span class="st0">&quot;Buzz: %d&quot;</span> % <span class="br0">&#40;</span>count<span class="br0">&#41;</span>
    <span class="kw1">elif</span> <span class="br0">&#40;</span>count % <span class="nu0">3</span> <span class="sy0">==</span> <span class="nu0">0</span><span class="br0">&#41;</span>:
        <span class="kw1">print</span> <span class="st0">&quot;Fizz: %d&quot;</span> % <span class="br0">&#40;</span>count<span class="br0">&#41;</span>
    <span class="kw1">else</span>:
        <span class="kw1">print</span> <span class="st0">&quot;Count is %d&quot;</span> % <span class="br0">&#40;</span>count<span class="br0">&#41;</span>
    count +<span class="sy0">=</span> <span class="nu0">1</span></pre></div></div></div></div></div></div></div>


]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/coding/2011/08/fizzbuzz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set Default Printer with Powershell</title>
		<link>http://codetwit.com/sysadmin/2011/07/set-default-printer-with-powershell/</link>
		<comments>http://codetwit.com/sysadmin/2011/07/set-default-printer-with-powershell/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 21:32:55 +0000</pubDate>
		<dc:creator>basketcase</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[printer]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=296</guid>
		<description><![CDATA[Quick, Dirty, Simple. Set the default printer with Powershell. Needed this as a part of a logon script to set default printer for certain users on a terminal server. ## Get the Printer with WMI $printer = Get-WmiObject -Query &#34;Select * from Win32_Printer Where Name = 'PDFCreator'&#34; &#160; ## Set printer as default printer $printer.SetDefaultPrinter&#40;&#41;]]></description>
			<content:encoded><![CDATA[<p>Quick, Dirty, Simple.  Set the default printer with Powershell.  Needed this as a part of a logon script to set default printer for certain users on a terminal server.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="powershell"><pre class="de1"><span class="co1">## Get the Printer with WMI</span>
<span class="re0">$printer</span> <span class="sy0">=</span> <span class="kw1">Get-WmiObject</span> <span class="kw5">-Query</span> <span class="st0">&quot;Select * from Win32_Printer Where Name = 'PDFCreator'&quot;</span>
&nbsp;
<span class="co1">## Set printer as default printer</span>
<span class="re0">$printer</span>.SetDefaultPrinter<span class="br0">&#40;</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>


]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/sysadmin/2011/07/set-default-printer-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dirtoday &#8211; Extended</title>
		<link>http://codetwit.com/coding/2011/07/dirtoday-extended/</link>
		<comments>http://codetwit.com/coding/2011/07/dirtoday-extended/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 02:12:11 +0000</pubDate>
		<dc:creator>basketcase</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[dirtoday extended]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=294</guid>
		<description><![CDATA[Extended version of Hal’s original “dirtoday” script via twitter https://twitter.com/#!/halr9000/status/88211937720156160 ## NAME: Dirtoday.ps1 ## AUTHOR: Barry Morrison ## LASTEDIT: 07/05/2011 16:18:33 &#60;# .Synopsis Get's files from today's date. Will also return narrowed results based on keyword .Description Get's files from today's date. Will also return narrowed results based on keyword .Parameter Path Will run in [...]]]></description>
			<content:encoded><![CDATA[<p>Extended version of Hal’s original “dirtoday” script via twitter https://twitter.com/#!/halr9000/status/88211937720156160</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="powershell"><pre class="de1"><span class="co1">## NAME: Dirtoday.ps1</span>
<span class="co1">## AUTHOR: Barry Morrison</span>
<span class="co1">## LASTEDIT: 07/05/2011 16:18:33</span>
<span class="coMULTI">&lt;#
 .Synopsis
 Get's files from today's date. Will also return narrowed results based on keyword
 .Description
 Get's files from today's date. Will also return narrowed results based on keyword
 .Parameter Path
 Will run in current directory. Path argument will allow you to define a path not in current working directory
 .Parameter Keyword
 Keyword argument will allow you to define a keyword to search on to narrow results.
 .Example
 PS C:\scripts &gt; .\dirtoday.ps1
&nbsp;
 Directory: C:\scripts
&nbsp;
 Mode LastWriteTime Length Name
 ---- ------------- ------ ----
 -a--- 7/5/2011 3:25 PM 114 cat
 -a--- 7/5/2011 4:11 PM 2252 dirtoday.ps1
 -a--- 7/5/2011 3:46 PM 848 dirtoday2.ps1
 -a--- 7/5/2011 2:55 PM 110 info.txt
 -a--- 7/5/2011 1:52 PM 37 test.foo
&nbsp;
 .Example
 PS C:\scripts &gt; .\dirtoday.ps1 -path &quot;c:\Users\John Doe\Pictures&quot;
&nbsp;
 Directory: C:\Users\John Doe\Pictures
&nbsp;
 Mode LastWriteTime Length Name
 ---- ------------- ------ ----
 -a--- 7/5/2011 11:05 AM 49888 weinerdog.jpg
&nbsp;
 .Example
 PS C:\scripts &gt; .\dirtoday.ps1 -keyword foo
&nbsp;
 cat:2:test.foo:1:blah, blah, foo, ice cream,
 test.foo:1:blah, blah, foo, ice cream,
&nbsp;
#&gt;</span>
&nbsp;
<span class="kw3">param</span><span class="br0">&#40;</span>
 <span class="br0">&#91;</span><span class="re3">string</span><span class="br0">&#93;</span><span class="re0">$Path</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">,</span>
 <span class="br0">&#91;</span><span class="re3">string</span><span class="br0">&#93;</span><span class="re0">$keyword</span> <span class="sy0">=</span> <span class="st0">&quot;&quot;</span>;
 <span class="br0">&#41;</span>
&nbsp;
<span class="co1">## Checking to see if the Keyword argument is passed -- If it is, search for $keyword</span>
<span class="kw3">if</span> <span class="br0">&#40;</span><span class="re0">$keyword</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
   <span class="re0">$files</span> <span class="sy0">=</span> <span class="kw2">dir</span> <span class="kw5">-Path</span> <span class="re0">$path</span> <span class="sy0">|</span> <span class="kw1">Where-Object</span> <span class="br0">&#123;</span> <span class="kw6">$_</span>.lastwritetime <span class="kw4">-ge</span> <span class="br0">&#40;</span><span class="kw1">get-date</span><span class="br0">&#41;</span>.date <span class="br0">&#125;</span> <span class="sy0">|</span> <span class="kw1">Select-String</span> <span class="re0">$keyword</span>
   <span class="co1">## If there are not results returned, tell me!</span>
   <span class="kw3">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="re0">$files</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
     <span class="kw1">Write-Output</span> <span class="st0">&quot;Nothing Here&quot;</span>
   <span class="br0">&#125;</span><span class="kw3">else</span><span class="br0">&#123;</span>
     <span class="co1">## If Results exist, give them to me!</span>
     <span class="re0">$files</span>
   <span class="br0">&#125;</span>
 <span class="br0">&#125;</span> <span class="kw3">else</span> <span class="br0">&#123;</span>
 <span class="co1">## If not keyword argument is passed, do a simple search</span>
   <span class="re0">$files</span> <span class="sy0">=</span> <span class="kw2">dir</span> <span class="kw5">-Path</span> <span class="re0">$path</span> <span class="sy0">|</span> <span class="kw1">Where-Object</span> <span class="br0">&#123;</span> <span class="kw6">$_</span>.lastwritetime <span class="kw4">-ge</span> <span class="br0">&#40;</span><span class="kw1">get-date</span><span class="br0">&#41;</span>.date <span class="br0">&#125;</span>
   <span class="co1">## Like above, checking to see if no results are found for the query</span>
   <span class="kw3">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="re0">$files</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
     <span class="co1">## Tell me if nothing exists</span>
     <span class="kw1">Write-Output</span> <span class="st0">&quot;Nothing Here&quot;</span>
   <span class="br0">&#125;</span><span class="kw3">else</span><span class="br0">&#123;</span>
     <span class="co1">## Write results if something exists</span>
     <span class="re0">$files</span>
  <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>


]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/coding/2011/07/dirtoday-extended/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hi, I&#8217;m a basket&#8230;I mean, I&#8217;m basketcase</title>
		<link>http://codetwit.com/musings/2011/07/hi-im-a-basket-i-mean-im-basketcase/</link>
		<comments>http://codetwit.com/musings/2011/07/hi-im-a-basket-i-mean-im-basketcase/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 02:05:29 +0000</pubDate>
		<dc:creator>basketcase</dc:creator>
				<category><![CDATA[Musings]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=315</guid>
		<description><![CDATA[I figure I should say who I am before I start slinging words out.  My name is Barry Morrison, and I work with Scott as a System&#8217;s Administrator.  I&#8217;ve been in IT since 2003, I&#8217;ve been in my current position since 2007.  My primary background is in Windows desktop/server administration, but my focus more so [...]]]></description>
			<content:encoded><![CDATA[<p>I figure I should say who I am before I start slinging words out.  My name is <a title="Barry Morrison's Website" href="http://www.barrymorrison.com" target="_blank">Barry Morrison</a>, and I work with Scott as a System&#8217;s Administrator.  I&#8217;ve been in IT since 2003, I&#8217;ve been in my current position since 2007.  My primary background is in Windows desktop/server administration, but my focus more so recently has been on storage (NetApp and Data Domain), backups and whatever else (that isn&#8217;t windows) I can get my hands on.  I&#8217;m very passionate about technology, combined with my short attention span, I like to play with everything.  I&#8217;ve recently taken a liking to Powershell (I hear the cringes now), and will now script everything I possibly can.  It has also helped me branch into other languages (Sh/Bash/Python &#8212; which I hope to do a lot more of).  So I&#8217;ll take it!</p>
<p>Why am I here?  Scott invited me, and we have a few ideas I think we&#8217;re both excited about regarding this particular blog space.  I think most of the code I write will be posted here, and less on my personal site going forward.  Seems more fitting here.  Thanks again Scott for the invite.  I hope I do your site justice!</p>
]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/musings/2011/07/hi-im-a-basket-i-mean-im-basketcase/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

