<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.5" -->
<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/"
	>

<channel>
	<title>Unix Mages</title>
	<link>http://unixmages.com</link>
	<description>Making Unix fun!</description>
	<pubDate>Fri, 20 Apr 2007 01:25:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>
	<language>en</language>
			<item>
		<title>Protective Spells</title>
		<link>http://unixmages.com/stories/protective-spells.html</link>
		<comments>http://unixmages.com/stories/protective-spells.html#comments</comments>
		<pubDate>Fri, 10 Nov 2006 10:53:00 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
		
		<category>Stories</category>

		<guid isPermaLink="false">http://dev.unixmages.com/wordpress/uncategorized/protective-spells.html</guid>
		<description><![CDATA[Welcome back to my classroom. Again, I am Professor Meotod, and today   it&#8217;s my pleasure to teach you about the various spells that protect   the scrolls and files you create and own. Before we discuss what the   spells are, I think it might be a good idea to review [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome back to my classroom. Again, I am Professor Meotod, and today   it&#8217;s my pleasure to teach you about the various spells that protect   the scrolls and files you create and own. Before we discuss what the   spells are, I think it might be a good idea to review why we must use   them. As some of you may know, not all mages are good. Some can be   mischievous, and others, alas, actively work against us. I wish it   were not so, but the choice is not mine to make. Deep in the past, the   arch mages who crafted Unix trusted and relied on each other, but knew   as the system grew, so would the number of people who used it. In   their wisdom, they crafted several tools that we can use to ensure   only the correct people are able to interact with our files.</p>

<p>Unix has two types of entities, users and groups. You may be familiar   with the &#8220;user&#8221; entity, as you are one. A user is typically an   individual with permissions to enter, or otherwise interact with the   tower. Groups are collections of users, meant to provide permissions   en masse. Do you belong to any groups? You can find out by muttering   &#8220;groups&#8221; at the command line, and you&#8217;ll get a list of all that you   belong to.</p>

<p>Now, as for the spells that we have at our disposal, a practical   application might prove more memorable than an old fool lecturing.   Lets all transport to our homes in the tower (using the &#8216;cd&#8217; spell by   itself will take you to your home). Inside our home directories,   create a room called &#8220;class&#8221; (the proper spell would be &#8216;mkdir class&#8217;)   and a room inside that, called &#8220;protection&#8221; (since the room will be   inside class, we want to mutter &#8216;mkdir class/protection&#8217;). Now, lets   transport to the directory (you&#8217;ve got it, &#8216;cd class/protection&#8217;). If   that seemed to take a long time, remember that in the future, as your   tutelage grows, you will learn all manner of shortcuts for doing what   you just did.</p>

<p>Alright, in our room, if we issue an &#8216;ls&#8217; spell, we see that it&#8217;s   empty, which makes sense since it was just created. Let us create a   scroll named &#8220;test&#8221; using the &#8216;touch&#8217; spell. Mutter &#8216;touch test&#8217;, then   issue an ls. You should see the scroll sitting there now. Be that as   it may, you are still missing a great deal of information about   &#8220;test&#8221;. Issue the &#8216;ls&#8217; spell again, but this time append &#8216;-l&#8217; to the   end of it, so that the spell is &#8216;ls -l&#8217;. Now you should see much of   what you were missing.</p>

<p>The first line may consist of &#8220;total 0&#8243;, which is merely referring to   how much space is being taken up. Since we just created the scroll, it   shouldn&#8217;t be much. Now, the next line is full of information. At the   far left, you have the current file permissions of the scroll. Lets   leave these for now, and also skip the second column, which will   probably be a &#8220;1&#8243;, and indicates the number of hard references to the   inode for that file. Dear me, I&#8217;m spouting gibberish. I&#8217;ll explain   myself at a later date, I assure you. In the meantime, forward to the   third column, which looks suspiciously like your name in the tower.   Indeed, that column displays who owns the scroll. The next column   should look somewhat familiar, as it should be the first thing you saw   when you cast the &#8216;groups&#8217; spell. That&#8217;s right, it reports which group   the file belongs to. The next column (fifth, if you&#8217;re counting) shows   how large the scroll is, in this case 0. After that comes the date and   timestamp of the last time you changed the scroll. Since all you did   was &#8216;touch&#8217; it, it should reflect what time the tower thought it was   when you created it.</p>

<p>Whew, that is a lot of information to take in at once. Let us step   back and look at the big picture again, before delving into details   once more. The &#8216;ls -l&#8217; spell gives you all the information you need to   know the status of any particular file in the tower at a glance. If   there are multiple files, each file gets it&#8217;s own line, so that the   information can be parsed easily by mages and spells alike. There also   exist spells to change every bit of information on that line, as well,   however only three of them deal with protection, and that&#8217;s what we&#8217;re   getting into next.</p>

<p>Now, let us examine in detail the first column of information we got   from the &#8216;ls -l&#8217; spell. If your output resembles my output, and I   suspect it does, it should look like this: -rw-r&#8211;r&#8211; . That may not   mean much to you right now, but it actually denotes the scroll&#8217;s   &#8220;permission set&#8221;, and here&#8217;s how it breaks down: &#8220;r&#8221; stands for &#8220;read   access&#8221;, &#8220;w&#8221; stands for &#8220;write access&#8221;, &#8220;x&#8221; (which doesn&#8217;t show up in   this case) stands for &#8220;execute access&#8221;, and &#8220;-&#8221; means &#8220;this permission   isn&#8217;t set&#8221;.</p>

<p>The way it is displayed on the line out put, it&#8217;s all run together,   and it makes it difficult for the beginning mage to analyze, so lets   break it up. The very first character (the &#8220;-&#8221;) is a flag that denotes   what type of file our scroll is. It&#8217;s unset, which means that it&#8217;s a   normal file. We can ignore it for right now. The next three characters   (&#8221;rw-&#8221;) show the permissions for the owner of the scroll, in this   case, you. The middle three (&#8221;r&#8211;&#8221;)are the permissions for the group   that the file belongs too (remember the fourth column from the &#8216;ls -l&#8217;   command?) and the last three (&#8221;r&#8211;&#8221;) are for everyone that isn&#8217;t you   and who doesn&#8217;t belong to the same group as the file. Simple, eh? I   thought not, let us break it down further.</p>

<p>Since there are nine characters we care about, and three &#8220;permission   sets&#8221; there, lets break it into groups of three:   <table><tr><td>   User</td><td>rw-</td></tr><tr><td>   Group</td><td>r&#8211;</td></tr><tr><td>   Others</td><td>r&#8211;</td></tr></table></p>

<p>What this table tells us is that the user who owns the file can read   and write to the file, the users in the group that the file belongs to   can read the file, and that everyone else can read the file as well.   Once we do that, it should be relatively easy to see how they all fit   together into rw-r&#8211;r&#8211;.</p>

<p>As you can see, there are a lot of blank, unset, permissions. If the   permissions were all set, it would look like this: &#8220;rwxrwxrwx&#8221;. As you   can see, the &#8220;r&#8221;s only go in the first columns, the &#8220;w&#8221;s in the   middle, and the &#8220;x&#8221;s at the end. This is because they are used as   &#8220;flags&#8221; to denote binary numbers. You don&#8217;t know binary? It&#8217;s very   simple:</p>

<p>Binary means base two, in other words, there are only two numbers,   zero (0) and one (1). As with base ten (what we normally use), when   you are counting and you run out of numbers, you add another column,   for instance: when we count, after we get to 9, there is no number for   &#8220;10&#8243;, so we have to use a &#8220;1&#8243; and a &#8220;0&#8243; to mean the same thing; in   binary, there is no number for &#8220;2&#8243; so they use a &#8220;1&#8243; and a &#8220;0&#8243; as   well. Here is how you would count in binary up to 7:</p>

<table border="1"><tr><td align="right">0</td><td>0</td></tr><tr><td align="right">1</td><td>1</td></tr><tr><td align="right">2</td><td>10</td></tr><tr><td align="right">3</td><td>11</td></tr><tr>4</td><td>100</td></tr><tr>5</td><td>101</td></tr><tr><td align="right">6</td><td>110</td></tr><tr><td align="right">7</td><td>111</td></tr></table>

<p>As you can see, since there are only two numbers, we add new columns a   lot. How does this tie into permissions in the tower? Simple! Look at   the user permission flags set: &#8220;rw-&#8221;, now imagine that each letter is   a &#8220;1&#8243; and each &#8220;-&#8221; is a &#8220;0&#8243;. You would get &#8220;110&#8243;, correct? Now, if you   look at the table above, you can see that &#8220;110&#8243; matches &#8220;6&#8243; in decimal   (base 10). The group and other flags (&#8221;r&#8211;&#8221; or &#8220;100&#8243;) match &#8220;4&#8243; from   the table, thus the permission set can be described as &#8220;644&#8243;.</p>

<p>Suppose for a moment that you were writing a scroll of sensitive   nature. Beyond the normal protections put in place on your home, you   wanted to ensure that no one aside from yourself could read the   scroll. Utilizing the &#8216;chmod&#8217; spell, you can ensure that by setting   the permissions to &#8220;rw&#8212;&#8212;-&#8221;. If we remember to convert the letters   to ones, and the -&#8217;s do zeroes, we wind up with 600, according to the   table above. This means that no one can do anything with the scroll   except ourselves (and the tower administrator).</p>

<p>Use this knowledge well, and practice it. Keep in mind, class, that it   is entirely possible to protect a scroll such that you yourself cannot   open it. In that event, it is still possible to alter the permissions   to correct that oversight.Thank you for your attention, and please   return for my next class, which I believe will be &#8220;Editing scrolls   using the &#8216;vi&#8217; spell&#8221;. Until then,</p>

<p>Your Professor,</p>

<p>Meotod</p>
]]></content:encoded>
			<wfw:commentRss>http://unixmages.com/stories/protective-spells.html/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Your Room in the Tower</title>
		<link>http://unixmages.com/stories/your-room-in-the-tower.html</link>
		<comments>http://unixmages.com/stories/your-room-in-the-tower.html#comments</comments>
		<pubDate>Sat, 04 Nov 2006 11:21:00 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
		
		<category>Stories</category>

		<guid isPermaLink="false">http://dev.unixmages.com/wordpress/uncategorized/your-room-in-the-tower.html</guid>
		<description><![CDATA[Hello. Allow me to introduce myself. My name is Professor Meotod, andI&#8217;ll be your instructor in several of the workings of the UnixSpellcraft. With luck and hard work, under my tutelage, you willadvance your knowledge to the point where it becomes easy for you tolearn new things outside of the classroom, and use them for [...]]]></description>
			<content:encoded><![CDATA[<p>Hello. Allow me to introduce myself. My name is Professor Meotod, andI&#8217;ll be your instructor in several of the workings of the UnixSpellcraft. With luck and hard work, under my tutelage, you willadvance your knowledge to the point where it becomes easy for you tolearn new things outside of the classroom, and use them for the goodof the tower. Perhaps even one day, you may decide to build your owntower. But first things first.</p>

<p>I have spoken with the tower manager, and you have been affordedpermanent lodging in the tower. Your room is located in the /homewing, and you can enter by speaking your name and password whenentering the tower.. For example, my room can be found at/home/meotod. Because of protective spells placed upon it, anyoneother than myself will have a difficult time obtaining entry. Youshould find that to be the case your rooms as well.Now, about your rooms. Your rooms will be the first place you seewhenever you enter the tower. All of your personal affects may bestored there, and should you ever decide to take up the art ofspell-smithing, these may be stored there as well.  Also, certainspells you invoke may create scrolls there, permitting them to act inways which you are able to change, by modifying the scrolls.</p>

<p>The most interesting part of your home in the castle is your abilityto create rooms inside of it. To create a room, utilize the &#8220;mkdir&#8221;spell. Since rooms are known as &#8220;directories&#8221; in the common parlance,it is shorthand for &#8220;make directory&#8221;. If you need help with remedialspells, remember to pick up a copy of &#8220;Unix for the Beginning Mage&#8221;.</p>

<p>Go to your room, and look around. You might not see much, besides acouple of rooms, and it looks pretty empty. That may be because you&#8217;renot looking for HIDDEN items. Assuming you are using &#8220;bash&#8221; as yourspellcasting environment (you can check by uttering the &#8220;ps&#8221; spell,and usually the first thing that is listed is your &#8220;shell&#8221;), then ascroll in your home directory will be created called .bash_history.Every time you cast a spell, or move about in the tower, it isrecorded on this scroll. Keep in mind that no one except yourself (andthe tower administrators) can read this. There are protective spellsguarding this scroll to prevent that from happening. If you don&#8217;t wishto read this scroll every time you want to look at your previousactions, the spell &#8220;history&#8221; can show you what you are looking for.</p>

<p>In addition to the .bash_history file, you may find others, dependingon the configuration of your tower. It is beyond the scope of thisclass to go into all that you are likely to find, however if you talkto a more experienced mage or wizard, or even your toweradministrator, they may be able to explain what the particular filesare.</p>

<p>I hope you enjoyed this brief walk through of your home in the tower,and come back for the next class, which is entitled &#8220;ProtectiveSpells&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://unixmages.com/stories/your-room-in-the-tower.html/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Coming Soon&#8230;</title>
		<link>http://unixmages.com/stories/coming-soon.html</link>
		<comments>http://unixmages.com/stories/coming-soon.html#comments</comments>
		<pubDate>Sat, 18 Feb 2006 08:42:00 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
		
		<category>Stories</category>

		<guid isPermaLink="false">http://dev.unixmages.com/wordpress/uncategorized/coming-soon.html</guid>
		<description><![CDATA[It was Friday night and a group of mages were lounging in /usr/local/games. Leal lined his shot up on the pool table when the cue ball nudged to the left.

&#8220;Hey, what gives?&#8221; he said.

&#8220;What?&#8221; Acre asked.

&#8220;The cue ball &#8212; it moved.&#8221;

Acre sighed. Leal had already spent ten minutes planning his turn.

&#8220;Well move it back and [...]]]></description>
			<content:encoded><![CDATA[<p>It was Friday night and a group of mages were lounging in <code>/usr/local/games</code>. Leal lined his shot up on the pool table when the cue ball nudged to the left.</p>

<p>&#8220;Hey, what gives?&#8221; he said.</p>

<p>&#8220;What?&#8221; Acre asked.</p>

<p>&#8220;The cue ball &#8212; it moved.&#8221;</p>

<p>Acre sighed. Leal had already spent ten minutes planning his turn.</p>

<p>&#8220;Well move it back and get on with the game.&#8221;</p>

<p>Leal fixed his shot. There was a subtle thump and the cue ball moved again.</p>

<p>&#8220;Hey!&#8221; Leal said.</p>

<p>Again, another thump &#8212; more louder this time.</p>

<p>Yiro looked up from his book.</p>

<p>&#8220;What is that?&#8221; he asked.</p>

<p>It was coming from the ceiling. The three mages looked up and listened as the thumps became more and more louder.</p>

<p>&#8220;Someone&#8217;s coming down the stairs.&#8221; Acre said.</p>

<p>&#8220;Or falling.&#8221; Yiro said.</p>

<p>The noise kept increasing and increasing until soon they could tell it was right outside the room. The door slammed open and in burst the owner of the Tower &#8212; a large, bald man who really didn&#8217;t understand the craft of Nix but knew the Tower somehow made him money.</p>

<p>He huffed and panted and looked around the room. Finally he caught his breath and pointed at one of the mages.</p>

<p>&#8220;You.&#8221; he said.</p>

<p>&#8220;Me?&#8221; Leal said.</p>

<p>&#8220;Tell me,&#8221; the owner said, &#8220;why can&#8217;t I talk to the Tower next door without walking over?&#8221;</p>

<p>&#8220;W-We-well&#8230; I don&#8217;t know.&#8221;</p>

<p>&#8220;Do something about that.&#8221;</p>

<p>And with that, the owner turned around and promptly left the room. The three mages looked at each other in bewilderment.</p>

<p>&#8220;Well, &#8221; Acre said finally, &#8220;I guess we should get started.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://unixmages.com/stories/coming-soon.html/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Of Mages and Mail, Part Three</title>
		<link>http://unixmages.com/stories/of-mages-and-mail-part-three.html</link>
		<comments>http://unixmages.com/stories/of-mages-and-mail-part-three.html#comments</comments>
		<pubDate>Wed, 14 Dec 2005 22:10:00 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
		
		<category>Stories</category>

		<guid isPermaLink="false">http://dev.unixmages.com/wordpress/uncategorized/of-mages-and-mail-part-three.html</guid>
		<description><![CDATA[We return back to the mail department of /var/spool/mail where the Mail Admin is finishing his lesson of email to the young mage, Acre.

&#8220;When a mage is finished writing an email, he hands it off to a daemon called smtpd. smtpd can be though of as the mailman of the Tower. Once smtpd is given [...]]]></description>
			<content:encoded><![CDATA[<p>We return back to the mail department of <code>/var/spool/mail</code> where the Mail Admin is finishing his lesson of email to the young mage, Acre.</p>

<p>&#8220;When a mage is finished writing an email, he hands it off to a daemon called <code>smtpd</code>. <code>smtpd</code> can be though of as the mailman of the Tower. Once <code>smtpd</code> is given an email, he goes on his way to deliver it.</p>

<p>&#8220;The first thing <code>smtpd</code> does is check to see where the email is going to. Next, he &#8211;&#8221;</p>

<p>&#8220;Wait, &#8221; Acre interrupted, &#8220;How does he know who the email is going to?&#8221;</p>

<p>&#8220;Er, right. Almost forgot about that part.  There&#8217;re these things called mail headers.&#8221;</p>

<p>&#8220;Mail headers.&#8221; Acre repeated.</p>

<p>The Admin continued, &#8220;Yes.  They&#8217;re lines of information at the beginning of every email.  They tell <code>smtpd</code> who the email is going to, where the email came from, the subject, and other delivery information.&#8221;</p>

<p>&#8220;What do they look like?&#8221;</p>

<p>&#8220;Well, like this:&#8221;</p>

<pre><code>To: joe@terrarum.net
From: admin@unixmages.com
Subject: Hello
</code></pre>

<p>There can be many more headers, but those are the bare minimum <code>smtpd</code> needs to get started on the delivery.  On the way, he&#8217;ll add some headers himself.&#8221; The Admin said.</p>

<p>Acre asked, &#8220;Like what?&#8221;</p>

<p>&#8220;Received Headers. Everytime an <code>smtpd</code> mailman gets an email, he tags it with a received email to say he handled that email at one time. It looks like this:&#8221;</p>

<pre><code>Received: from [192.168.1.2] (tower1.unixmages.com)         
    by mail.unixmages.com with SMTP id ; Thu, 15 Dec 2005 02:21:27 +0000
</code></pre>

<p>&#8220;What&#8217;s all that mean?&#8221; Acre asked.</p>

<p>&#8220;It simply says what Tower sent the email and what Tower is going to handle the mail. <code>smtpd</code> also gives it a unique ID to refer to it from now on and tags it with a date.&#8221; The Admin replied.</p>

<p>&#8220;I got it, &#8221; Acre said, &#8220;Now what does <code>smtpd</code> do after it gets a new email to deliver?&#8221;</p>

<p>&#8220;First, he looks at the To: header and notes the domain name &#8212; the part of the email address after the @ sign. In this case, the email is going to terrarum.net. After <code>smtpd</code> knows the domain name, he needs to find out how to get there.  He does this by looking up an <code>MX</code> record for that domain. MX stands for Mail Exchange and it lets <code>smtpd</code> know what Tower handles email for a certain domain.&#8221;</p>

<p>&#8220;Can we look up <code>MX</code> records ourself?&#8221; Acre asked.</p>

<p>&#8220;Sure can,&#8221; The Admin said.  &#8220;Just cast this spell:&#8221;</p>

<pre><code>$ dig -t mx +short terrarum.net
10 terrarum.net.
</code></pre>

<p>&#8220;This tells us that the Tower <code>terrarum.net</code> handles mail for itself.&#8221; The Admin said.</p>

<p>&#8220;So Towers can handle mail for other domains besides their own?&#8221; Acre asked.</p>

<p>The Admin replied, &#8220;Definitely. Sometimes a Tower just doesn&#8217;t have the resources to handle it&#8217;s own mail, so it lets another Tower do that work.&#8221;</p>

<p>&#8220;I get it.&#8221; Acre said..</p>

<p>&#8220;Good! After <code>smtpd</code> knows which Tower to deliver the mail to, it walks over and talks to that Towers <code>smtpd</code> mailman.&#8221;</p>

<p>Acre asked, &#8220;Does every Tower have a mailman?&#8221;</p>

<p>&#8220;Technically every Unix Tower has a mailman even if it doesn&#8217;t handle email. All modern Towers handle some type of mail &#8212; even if it&#8217;s internal &#8212; but <code>smtpd</code> can only talk to the mailmen of Towers that handle public mail.&#8221;</p>

<p>Acre said, &#8220;OK, got it. Now what happens when the two mailmen talk to each other?&#8221;</p>

<p>&#8220;Nothing too exciting. Basically the visiting mailman introduces himself and hands the email over.  The destination mailman looks at it and decides if he wants it or not.  If he does, he&#8217;ll simply place the mail into the mages mailbox. If not, he&#8217;ll simply ignore the visiting mailman.&#8221;</p>

<p>&#8220;That&#8217;s kind of rude..&#8221; Acre said.</p>

<p>&#8220;Well in this day of junk mail, not all mailmen are nice.&#8221; The Admin replied.</p>

<p>&#8220;So that&#8217;s it then?&#8221; Acre asked. &#8220;The email gets placed in the mailbox and the mage simply reads it using the ways we talked about earlier?&#8221;</p>

<p>&#8220;Yep, the mail cycle is complete!&#8221;</p>

<p>Acre thought for a bit. &#8220;You know, this all sounds like a fancy way of working with text files.&#8221;</p>

<p>The Admin said, &#8220;In a way, it&#8217;s exactly that:&#8221;</p>

<table width="100%"><tr><th>Files</th><th>Email</th></tr><tr><td>vi, nano, pico</td><td>Mail Program</td></tr><tr><td>mv</td><td>smtpd</td></tr><tr><td>cat, less</td><td>imapd, popd, Mail Program</td></tr></table>

<p>&#8220;Wow, that&#8217;s not so hard at all!&#8221; Acre said.</p>

<p>&#8220;Nope, email is actually pretty simple.  Unfortunately it can get difficult with blocking viruses and spam. And there are some advanced email topics, too, but we&#8217;ll get to those another day.&#8221; The Admin finished.</p>
]]></content:encoded>
			<wfw:commentRss>http://unixmages.com/stories/of-mages-and-mail-part-three.html/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Of Mages and Mail, Part Two</title>
		<link>http://unixmages.com/stories/of-mages-and-mail-part-two.html</link>
		<comments>http://unixmages.com/stories/of-mages-and-mail-part-two.html#comments</comments>
		<pubDate>Wed, 14 Dec 2005 22:06:00 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
		
		<category>Stories</category>

		<guid isPermaLink="false">http://dev.unixmages.com/wordpress/uncategorized/of-mages-and-mail-part-two.html</guid>
		<description><![CDATA[The two mages returned from their break and the Admin continued his explanation of the Unix mail system.

&#8220;There are a few different ways a mage can read his mail on a Unix system.  The first, and simplest, is with the mail spell.

&#8220;When the mail spell is cast, it will either tell the mage they [...]]]></description>
			<content:encoded><![CDATA[<p>The two mages returned from their break and the Admin continued his explanation of the Unix mail system.</p>

<p>&#8220;There are a few different ways a mage can read his mail on a Unix system.  The first, and simplest, is with the <code>mail</code> spell.</p>

<p>&#8220;When the <code>mail</code> spell is cast, it will either tell the mage they have no mail, or if they do, place them in a new mail shell.</p>

<p>&#8220;Here&#8217;s what it looks like when the mage has no mail:&#8221;</p>

<pre><code>$ mail
No mail for joe
</code></pre>

<p>&#8220;And here&#8217;s what it looks like when there&#8217;s actually mail:</p>

<pre><code>$ mail
Mail version 8.1 6/6/93.  
Type ? for help.

"/var/spool/mail/joe": 1 message 1 new
&gt;N  1 admin@unixmages.com  Sun Dec 11 11:54  14/565   "hi" 
N  2 admin@unixmages.com  Sun Dec 11 12:26  14/604   "hi again"
&amp;
</code></pre>

<p>&#8220;The ampersand (&#38;) is the prompt in the mail shell.  Above that, mail tells us what messages the mage has in their inbox. <code>N</code> stands for &#8220;new&#8221; and the number next to it is that messages position in the inbox.</p>

<p>&#8220;To read a message, we simply type the messages number at the prompt:&#8221;</p>

<pre><code>&amp; 1
Message 1:
From admin@unixmages.com  Sun Dec 11 12:25:59 2005
X-Original-To: joe
Delivered-To: joe@unixmages.com
To: joe@unixmages.com
Subject: hi
Date: Sun, 11 Dec 2005 12:25:59 -0500 (EST)
From: admin@unixmages.com

hello, this is a test message

&amp;
</code></pre>

<p>&#8220;To delete a message, use the <code>d</code> command:&#8221;</p>

<pre><code>&amp; d 1
</code></pre>

<p>&#8220;To quit, type <code>q</code>.&#8221;</p>

<pre><code>&amp; q
$
</code></pre>

<p>&#8220;You can also send new mail and reply to messages with the <code>mail</code> spell.  For more information on it, type help at the mail prompt.&#8221;</p>

<p>Acre said, &#8220;So basically, the <code>mail</code> spell is just a fancy spell that does the same thing as casting <code>cat</code> and <code>less</code> manually in the mailbox.&#8221;</p>

<p>&#8220;Yep, <code>mail</code> just provides a nice shell.  And don&#8217;t forget, you can send mail with <code>mail</code>, too.&#8221;</p>

<p>&#8220;OK, but to use the <code>mail</code> spell, doesn&#8217;t the mage have to be in the Tower where the mail is kept?&#8221;, Acre asked.</p>

<p>&#8220;Yes, that&#8217;s correct.&#8221; The Admin replied.</p>

<p>Acre said, &#8220;So what if the mage is at their house or away from the Tower?&#8221;</p>

<p>&#8220;Mages can still check their mail, but they&#8217;ll need help from some daemons.&#8221;</p>

<p>&#8220;Which ones?&#8221;</p>

<p>&#8220;Two actually: <code>imapd</code> and <code>popd</code>&#8220;</p>

<p>&#8220;What are the differences?&#8221;, Acre asked?</p>

<p>&#8220;<code>popd</code> (also known as <code>popd3</code>, since that&#8217;s the current version of the protocol) is more simple than <code>imapd</code>.  It takes less resources in the Tower to use, and has been around longer.  <code>imapd</code>, on the other hand, might be more complex, but provides more features in return.&#8221;</p>

<p>&#8220;What kind of features?&#8221;</p>

<p>&#8220;Well, when a mage checks their mail with <code>pop3</code>, all the mail is transferred to where the mage is, and is then removed from the Towers mail department. If the mage somehow loses their mail, it&#8217;s lost forever &#8212; the Tower has no record of it anymore. <code>imap</code> can fix that problem by allowing the mage to check their mail from a different location while still having the mail stored at the Tower.  <code>imap</code> can also handle shared mailboxes and multiple mailboxes easily. While it is possible to leave mail at the Tower using <code>pop</code>, it doesn&#8217;t work as smoothly as <code>imap</code> and still creates a 2nd copy at the mage&#8217;s location, taking up space.&#8221;</p>

<p>Acre asked, &#8220;I see. So <code>imap</code> is more preferred?&#8221;</p>

<p>&#8220;It&#8217;s very easy for a Tower to use both <code>pop</code> and <code>imap</code> and let the mage decide. From the mage&#8217;s perspective, <code>imap</code> provides more features and is really the better choice &#8212; unless they&#8217;re in a situation where <code>pop</code> is the only option.&#8221;</p>

<p>&#8220;So how does each one work?&#8221; Acre asked.&#8221;</p>

<p>The Admin replied, &#8220;The mage will have to set up a mail program wherever they are. Once he tells the mail program some information about himself, the Tower to get the mail from, and whether to use <code>pop</code> or <code>imap</code>, the program will do the rest of the dirty work.  We can actually see some of that work here.</p>

<p>&#8220;Here&#8217;s what a <code>pop</code> session looks like:&#8221;</p>

<pre><code>$ telnet pop3.unixmages.com 110

Trying 127.0.0.1...Connected to pop3.unixmages.com
Escape character is '^]'.
+OK POP3 ready.
user joe
+OK
pass p4ssw0rd
+OK Logged in.
list
1 44582 38183 16574 15348
quit
+OK Logging out.
</code></pre>

<p>&#8220;And here&#8217;s an <code>imap</code> session:&#8221;</p>

<pre><code>$ telnet imap.unixmages.com 143
Trying 127.0.0.1...
Connected to imap.unixmages.com
* OK IMAP ready.
a1 login joe p4ssw0rd
a1 OK Logged in.
a2 select INBOX
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)]  Flags permitted.
* 26 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1086774200] UIDs valid
* OK [UIDNEXT 10400] Predicted next UID
a2 OK [READ-WRITE] Select completed.
a3 logout
* BYE Logging out
a3 OK Logout completed.
</code></pre>

<p>&#8220;As you can see, they work in two completely different ways.&#8221; the Admin said.&#8221;</p>

<p>&#8220;What&#8217;s all that <code>telnet</code> stuff?&#8221; Acre asked.</p>

<p>&#8220;<code>telnet</code> is a spell to let us talk to Towers remotely. <code>pop3.unixmages.com</code> and <code>imap.unixmages.com</code> are the two places we&#8217;re talking to.  The number at the end is a port. We&#8217;ll learn about ports later &#8212; but just for now, remember that <code>110</code> and <code>143</code> are the port numbers for popd and imapd.&#8221;</p>

<p>&#8220;So <code>popd</code> and <code>imapd</code> &#8212; these two daemons allow a mage to connect to a remote Tower to check their mail. Basically, what they&#8217;re doing is teleporting over to the Tower and allowing the mage&#8217;s mail program to use fancy versions of the <code>cat</code> or <code>less</code> spells to read those text files in their mailbox. Right?&#8221;</p>

<p>&#8220;You got it.&#8221; The Admin said.</p>

<p>Acre said, &#8220;OK, I get it. Now what about mail services like gmail and yahoo that let you check your mail over the web. How do those work?&#8221;</p>

<p>&#8220;Basically the same way as using a full mail program. Those services still use mailboxes and <code>popd</code> and <code>imapd</code>, but they output all the mail to a webpage.&#8221;</p>

<p>&#8220;Got it.&#8221;, Acre said, &#8220;Now how does someone send me mail and how does it get to my mailbox?&#8221;</p>

<p>&#8220;We&#8217;ll go over that topic next.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://unixmages.com/stories/of-mages-and-mail-part-two.html/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Of Mages and Mail, Part One</title>
		<link>http://unixmages.com/stories/of-mages-and-mail-part-one.html</link>
		<comments>http://unixmages.com/stories/of-mages-and-mail-part-one.html#comments</comments>
		<pubDate>Wed, 14 Dec 2005 22:02:00 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
		
		<category>Stories</category>

		<guid isPermaLink="false">http://dev.unixmages.com/wordpress/uncategorized/of-mages-and-mail-part-one.html</guid>
		<description><![CDATA[It was Acre&#8217;s first day of training in the Towers mail department over at /var/spool/mail.  This is where all the mail is stored and waits to be retrieved by the POP and IMAP daemons.

&#8220;How do these mailboxes work?&#8221; Acre asked the admin on duty.

&#8220;Well,&#8221; the admin replied, &#8220;it&#8217;s really not that complicated.  Our [...]]]></description>
			<content:encoded><![CDATA[<p>It was Acre&#8217;s first day of training in the Towers mail department over at <code>/var/spool/mail</code>.  This is where all the mail is stored and waits to be retrieved by the POP and IMAP daemons.</p>

<p>&#8220;How do these mailboxes work?&#8221; Acre asked the admin on duty.</p>

<p>&#8220;Well,&#8221; the admin replied, &#8220;it&#8217;s really not that complicated.  Our Tower users a mail storage format known as <code>maildir</code>.&#8221;</p>

<p>&#8220;<code>maildir</code>?&#8221;</p>

<p>&#8220;Mail Directory. It allows us to keep the mail very organized and secure.&#8221; the admin replied.</p>

<p>&#8220;&#8216;Secure&#8217; as in no one can read it?&#8221; Acre asked.</p>

<p>&#8220;No, people can still read it if the wrong permissions are set. But by secure, I mean it&#8217;s harder to corrupt and lose mail like it is with the other storage format.&#8221;</p>

<p>&#8220;What other format is that?&#8221;</p>

<p>&#8220;<code>mbox</code>.&#8221; the Admin said.</p>

<p>Acre thought for a bit.</p>

<p>&#8220;So there are two formats: <code>maildir</code> and <code>mbox</code>. How do either work?&#8221; he asked.</p>

<p>&#8220;Lets start with <code>mbox</code>.  In most towers, a Mage&#8217;s mailbox is named the login name of the mage.&#8221;</p>

<p>&#8220;So mine would be acre.&#8221; Acre said.</p>

<p>&#8220;Correct. And that&#8217;s located at <code>/var/spool/mail/acre</code>.  Now that mailbox is just a plain text file with all your email in it.  It kind of looks like this:&#8221;</p>

<pre><code>From root@localhost  Sat Nov 12 12:22:21 2005
Return-Path: root@localhost
From: root@localhost
Received: by localhost@localdomain
Subject: Email Message 1This is email number one
From joe@unixmages.com  Sat Nov 12 12:33:21 2005
Return-Path: joe@unixmages.com
From: joe@unixmages.com
Received: by localhost@localdomain

Subject: Email Message 2

This is email number two
</code></pre>

<p>&#8220;So as you can see, all your email is just placed in one big file.&#8221; the Admin said.</p>

<p>&#8220;That looks like it can get sloppy.&#8221;</p>

<p>&#8220;Oh it can. Mailboxes can get really big and if one email is corrupt, it ruins all the other email.&#8221;</p>

<p>&#8220;So is that why we use <code>maildir</code> instead?&#8221; Acre asked.</p>

<p>&#8220;Yes, <code>maildir</code> solves a lot of the problems mbox has.&#8221;</p>

<p>&#8220;And how does <code>maildir</code> work?&#8221;</p>

<p>&#8220;Well, instead of your mailbox, <code>/var/spool/mail/acre</code>, being a text file, it&#8217;s a directory. And inside that directory are 3 subdirectories:&#8221;</p>

<pre><code># ls /var/spool/mail/acre
cur new tmp
</code></pre>

<p>&#8220;3 directories.&#8221; the Admin continued, &#8220;<code>new</code> is where all the mail you haven&#8217;t read yet goes.  After you read it, the message gets placed in to <code>cur</code>.  When the mail is being delivered, it uses <code>tmp</code> as a temporary area so the delivery doesn&#8217;t interfere with other mail. If, for some reason, a message is stuck in tmp for a really long time (like a few days), something is definitely wrong with that message.</p>

<p>&#8220;Finally, instead of all mail being stored in one big file, each message gets it&#8217;s own text file. So if one message is corrupt, it doesn&#8217;t bother any of the other messages.&#8221; the Admin finished.</p>

<pre><code># ls /var/spool/mail/acre/new
1130981120.V801I40ba9M194107.unixmages.com
# cat /var/spool/mail/acre/new/1130981120.V801I40ba9M194107.unixmages.com

From root@localhost  Sat Nov 12 12:22:21 2005
Return-Path: root@localhostFrom: root@localhost
Received: by localhost@localdomain
Subject: Email Message 1

This is email number one
</code></pre>

<p>&#8220;Why is the name of the email so weird?&#8221; Acre asked.</p>

<p>&#8220;It makes sense to the mail system.  It includes the date the message was sent, the name of the domain the message belongs to, and some other internal information. It all helps the organization of the mail system.&#8221;</p>

<p>&#8220;I get it. So if this is how email is stored, how is it picked up?&#8221; asked Acre.</p>

<p>&#8220;We&#8217;ll take a break and I&#8217;ll explain that part later.&#8221; the Admin said.</p>

<p>References:</p>

<p><a href="http://en.wikipedia.org/wiki/Mbox" title="mbox format">mbox</a></p>

<p><a href="http://cr.yp.to/proto/maildir.html" title="maildir format">maildir</a></p>
]]></content:encoded>
			<wfw:commentRss>http://unixmages.com/stories/of-mages-and-mail-part-one.html/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Run-in With Crond</title>
		<link>http://unixmages.com/stories/a-run-in-with-crond.html</link>
		<comments>http://unixmages.com/stories/a-run-in-with-crond.html#comments</comments>
		<pubDate>Wed, 14 Dec 2005 22:02:00 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
		
		<category>Stories</category>

		<guid isPermaLink="false">http://dev.unixmages.com/wordpress/uncategorized/a-run-in-with-crond.html</guid>
		<description><![CDATA[It was late at night when the Young Mage was walking through the Tower.  Wandering aimlessly, he stared at the looming walls, spiraling staircases, and catwalks when, all of the sudden, he heard a buzzing from above.

Tumbling through the air, it looked like a small robot was making it&#8217;s way down toward the Mage. [...]]]></description>
			<content:encoded><![CDATA[<p>It was late at night when the Young Mage was walking through the Tower.  Wandering aimlessly, he stared at the looming walls, spiraling staircases, and catwalks when, all of the sudden, he heard a buzzing from above.</p>

<p>Tumbling through the air, it looked like a small robot was making it&#8217;s way down toward the Mage. The little gizmo finally made it to the mage and bobbed up and down about a foot above his head.</p>

<p>&#8220;Hello!&#8221; the robot said.</p>

<p>&#8220;Um.. Hi&#8221; the Mage replied.</p>

<p>&#8220;Nice night, isn&#8217;t it?&#8221;</p>

<p>&#8220;Sure, I suppose. Um.. who are you?&#8221; the Mage asked.</p>

<p>&#8220;I&#8217;m a daemon. My name is Crond&#8221; the robot replied.</p>

<p>&#8220;Oh, a daemon! I learned about daemons! You guys work in the Tower and do various jobs.&#8221;</p>

<p>&#8220;That&#8217;s right!&#8221; Crond said.</p>

<p>&#8220;And just what job do you do, Crond?&#8221; the Mage asked.</p>

<p>&#8220;I make sure things get done at a specific time.&#8221;</p>

<p>&#8220;Oh, how&#8217;s that work?&#8221;</p>

<p>&#8220;Well, Mages, like yourself, tell me they need something done at a certain time, and I do it.&#8221; Crond explained.</p>

<p>&#8220;I see. So a Mage just walks up to you and says they need something done and that&#8217;s it?&#8221; the Mage asked.</p>

<p>&#8220;Well, they need to fill out a form.&#8221;</p>

<p>&#8220;A form?&#8221;</p>

<p>&#8220;Yep, a crontab form. After they fill it out, they&#8217;re all set.&#8221;</p>

<p>&#8220;Well what does the form look like?&#8221;</p>

<p>&#8220;It looks a little something like this:&#8221;</p>

<pre><code>minute hour day month weekday job
</code></pre>

<p>where:</p>

<pre><code>minute = minute (0-59)
hour = hour (0-23)
day = day of the month (1-31)
month = month (1-12)
weekday = day of the week (0-7 where 0 and 7 are both sunday. or use names like mon,tue,wed)
job = job -- the path to the script or program you want to run
</code></pre>

<p>&#8220;See?&#8221; Crond explained, &#8220;They just fill in the sections and that&#8217;s it. So for instance, if a Mage wanted me to start his laundry every Sunday at 9 AM, the form would look like this:&#8221;</p>

<pre><code>0 9 * * 7 /usr/local/bin/laundry.sh
</code></pre>

<p>&#8220;What do the stars and zeros mean?&#8221; the Mage asked.</p>

<p>&#8220;That star is the same as the wildcard star &#8212; it means anything. So the stars in the laundry form mean &#8216;Every day of the month and every month of the year&#8217;. Since the Mage then specified Sunday, I&#8217;ll only run it on Sundays &#8212; but if he didn&#8217;t I&#8217;d start his laundry every day all year long at 9 AM.  The zero just means to start it at 9 AM exactly &#8212; not 9:01 or 9:43.&#8221;</p>

<p>&#8220;I see,&#8221; the Mage said. &#8220;So if I needed to be woke up at 6:00 AM every day, I would fill out a from like this:&#8221;</p>

<pre><code>0 6 * * * /usr/local/bin/alarm-clock.sh
</code></pre>

<p>&#8220;Yep,&#8221; Crond replied, &#8220;but I&#8217;m sure you want to sleep in on the weekends, so you can tell me that you want woke up only on weekdays like so:&#8221;</p>

<pre><code>0 6 * * 1-5 /usr/local/bin/alarm-clock.sh
</code></pre>

<p>&#8220;The 1-5 means Monday through Friday.&#8221; Crond said.</p>

<p>&#8220;OK, but sometimes I hit the snooze button too. Can you do that?&#8221; the Mage asked.</p>

<p>&#8220;Sure can, just like this:&#8221;</p>

<pre><code>0,5,10 6 * * 1-5 /usr/local/bin/alarm-clock.sh
</code></pre>

<p>&#8220;Then I&#8217;ll set your alarm off every 5 minutes up until 6:15 AM.&#8221; Crond said.</p>

<p>&#8220;OK, and if I wanted to snooze the whole hour, would it be:&#8221;</p>

<pre><code>0,5,10,15,20,25,30,35,40,45,50,55 6 * * 1-5 /usr/local/bin/alarm-clock.sh
</code></pre>

<p>&#8220;Yes,&#8221; Crond said, &#8220;that&#8217;ll work, but it&#8217;s easier to just do this:&#8221;</p>

<pre><code>*/5 6 * * 1-5 /usr/local/bin/alarm-clock.sh
</code></pre>

<p>&#8220;OK, I get it.&#8221; the Mage replied. &#8220;You&#8217;re a pretty useful daemon! How can I ever get a hold of you if I need to fill a form out?&#8221;</p>

<p>&#8220;Just cast this spell:&#8221;</p>

<pre><code>crontab -e
</code></pre>

<p>&#8220;That will bring up a text-editor and you can just fill out the form on the next empty line. It&#8217;s as easy as that!&#8221; Crond said.</p>

<p>&#8220;Sounds like it!&#8221; said the Mage. &#8220;By the way, what are you doing flying around the Tower anyways?&#8221;</p>

<p>Crond handed the Mage a crontab form that contained:</p>

<pre><code>0 22 * * 1-5 /usr/local/bin/curfew.sh
</code></pre>

<p>&#8220;Oh, well I better be getting back then,&#8221; the Mage said, &#8220;Thanks again for all your help!&#8221;</p>

<p>&#8220;No problem!&#8221; Crond replied, &#8220;Those are just the basics of me. If you want to learn more, cast the following spell:&#8221;</p>

<pre><code>man 5 crontab
</code></pre>

<p>And with that, the gears on Crond wound up faster and off he flew.</p>
]]></content:encoded>
			<wfw:commentRss>http://unixmages.com/stories/a-run-in-with-crond.html/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
