<?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>1000umbrellas.com &#187; stdin</title>
	<atom:link href="http://1000umbrellas.com/tag/stdin/feed" rel="self" type="application/rss+xml" />
	<link>http://1000umbrellas.com</link>
	<description>Michael Descy&#039;s Personal Website</description>
	<lastBuildDate>Fri, 15 Jul 2011 02:06:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<atom:link rel='hub' href='http://1000umbrellas.com/?pushpress=hub'/>
		<item>
		<title>How to Redirect Output from Command-line Processes</title>
		<link>http://1000umbrellas.com/2010/06/24/how-to-redirect-output-from-command-line-processes</link>
		<comments>http://1000umbrellas.com/2010/06/24/how-to-redirect-output-from-command-line-processes#comments</comments>
		<pubDate>Thu, 24 Jun 2010 20:39:33 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[/dev/null]]></category>
		<category><![CDATA[2>&1]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[emails from cron]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[stdin]]></category>
		<category><![CDATA[stdout]]></category>

		<guid isPermaLink="false">http://1000umbrellas.com/?p=884</guid>
		<description><![CDATA[This is definitely a newb-level topic, but I think it is important to understand how to redirect output from your command-line processes. This becomes important because regularly-schedule processes run via cron will email you whatever the output is. This is completely confusing when you first encounter it, and the complete solution isn&#8217;t exactly obvious.
StdOut
When you [...]]]></description>
			<content:encoded><![CDATA[<p>This is definitely a newb-level topic, but I think it is important to understand how to redirect output from your command-line processes. This becomes important because regularly-schedule processes run via cron will email you whatever the output is. This is completely confusing when you first encounter it, and the complete solution isn&#8217;t exactly obvious.</p>
<h2>StdOut</h2>
<p>When you run a process on the command line, it will probably output right back to the terminal. This is StdOut, or &#8220;standard output.&#8221; In scripts and cron jobs, however, you might want to redirect output to a file instead, so you can review the output later.</p>
<p>You can redirect output to a new file by using the &#8220;&gt;&#8221; operator.</p>
<p><code>$ ls -l &gt; ~/directory_listing.txt</code></p>
<p>You can redirect output and <em>append</em> it to a file by using the &#8220;&gt;&gt;&#8221; operator. This method will create a file if it does not already exist.</p>
<h2>StdErr</h2>
<p>Error messages are output to StdErr, which by default is redirected to StdOut. This is why you see normal messages and error messages in the terminal when you run a command. StdErr does not have to be redirected to StdOut, however, and has to be treated separately from StdOut if you are redirecting StdOut.</p>
<h2>/dev/null and 2&gt;&amp;1</h2>
<p>Redirecting output to /del/null sends it nowhere, which effectively gets rid of it. You often see output redirected to /dev/null, followed by a cryptic construction <code>2&gt;&amp;1</code>. Here is what <a href="http://docstore.mik.ua/orelly/unix/upt/ch08_13.htm" target="_blank">that construction means</a>:</p>
<p>In the command<br />
<code>$ tvnamer --batch &gt; ~/log/tvnamer.log 2&gt;&amp;1</code></p>
<ul>
<li>2 refers to StdErr; and</li>
<li><code>&amp;1</code> refers to the first redirection argument; in this case, /log/tvnamer.log.</li>
</ul>
<p>My example uses a normal file, instead of /dev/null, to show that you can use  <code>2&gt;&amp;1</code> with any old file.</p>
<p>This construction is very useful if you find that your cron jobs are sending you emails, even after you redirected their output to log files. Cron will automatically email the owner of the cron job any output (on StdOut) from them. This is why you sometimes are notified that you have emails when you log into your system. Effective redirection will eliminate these emails.</p>
]]></content:encoded>
			<wfw:commentRss>http://1000umbrellas.com/2010/06/24/how-to-redirect-output-from-command-line-processes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

