<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>NixTutor</title>
	
	<link>http://www.nixtutor.com</link>
	<description>Helping you Learn Linux</description>
	<lastBuildDate>Wed, 07 Oct 2009 11:00:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Nixtutor" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="nixtutor" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">Nixtutor</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Your Chance to Contribute to an Open Source Project</title>
		<link>http://www.nixtutor.com/linux/your-chance-to-contribute-to-an-open-source-project/</link>
		<comments>http://www.nixtutor.com/linux/your-chance-to-contribute-to-an-open-source-project/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 11:00:41 +0000</pubDate>
		<dc:creator>Mark Sanborn</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.nixtutor.com/?p=1153</guid>
		<description><![CDATA[A chance to work on an open source easy to use site monitor written in Python.
No related posts.]]></description>
			<content:encoded><![CDATA[<p>I originally created a simple site monitoring Python script and posted it up to github as a &#8220;gist&#8221;: <a href="http://gist.github.com/177420">177420</a>.  It was then improved by <a href="http://github.com/emwendelin">Eric Wendelin</a> who forked my original gist and made it better in this gist: <a href="http://gist.github.com/187610">187610 </a>.</p>
<p>Eric had made the script much more &#8220;pythonic&#8221; and really made the code more usable and expendable which he explains in his blog post, <a href="http://eriwen.com/python/site-monitor/">Site monitoring with Python and cron</a>.  He had made the script accept command line arguments and even added a way to send email through Python if you didn&#8217;t want to setup your own mail daemon.</p>
<p>I thought his additions were a great example of open source coding in action.</p>
<h2>What does this have to do with Nix?</h2>
<p>Well on the surface it doesn&#8217;t directly relate to Linux.  The project itself is more useful for web designers and people that host websites; however, I thought this was a perfect example of open source coding and wanted to share it with you.  Open source code and community programming is what Linux was made from.  This project doesn&#8217;t contribute to the Linux kernel or anything super important but it is a very simple script that is now open to the public for review and improvement.</p>
<h2>Ever wanted to contribute to a project but didn&#8217;t know where to start?</h2>
<p>If you ever wanted to contribute and feel part of an open source community now is your chance.  I feel like this is a very small project and it could be improved by ANYONE with the smallest amount of Python experience.  We are not asking you to know how a kernel works or for you to start writing device drivers, just a simple Python script.  This is a great opportunity for you to learn the nature of open source software and the community that powers Linux and some of the best programs around.</p>
<p>I&#8217;m even going to give you the steps you need to get going!</p>
<h3 class="small">Download Git</h3>
<p><a href="apt:git">Download Git</a>.  (sudo apt-get install git)</li>
<h3 class="small">Clone the Project</h3>
<div class="term">git clone git://github.com/sanbornm/Site-Monitor.git</div>
<h3 class="small">Make Changes</h3>
<p>Now make some changes.</p>
<p>Something I personally would like to see in this code is the ability to generate a graph of response times.  Other things could include:</p>
<ul>
<li>Threshold for alert on slow response time</li>
<li>Support for a config file</li>
</ul>
<h2>I am not a Programmer but I still want to contribute!</h2>
<p>If you are not a programmer but still want to contribute to the open source community and learn a little about how it all works please consider going to <a href="http://github.com/sanbornm/Site-Monitor">the project website</a> and submit a feature request (click create issue).  This will give us an idea about what you would like to see in the script and help shape future versions.</p>
<p>See you in the open source community!</p>
<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/OMK1VHGanHpu0nOjjl2NUs9xCOs/0/da"><img src="http://feedads.g.doubleclick.net/~a/OMK1VHGanHpu0nOjjl2NUs9xCOs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/OMK1VHGanHpu0nOjjl2NUs9xCOs/1/da"><img src="http://feedads.g.doubleclick.net/~a/OMK1VHGanHpu0nOjjl2NUs9xCOs/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.nixtutor.com/linux/your-chance-to-contribute-to-an-open-source-project/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automatically Take a Screenshot and Make it Public using Dropbox</title>
		<link>http://www.nixtutor.com/linux/automatically-take-a-screenshot-and-make-it-public-using-dropbox/</link>
		<comments>http://www.nixtutor.com/linux/automatically-take-a-screenshot-and-make-it-public-using-dropbox/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 11:00:41 +0000</pubDate>
		<dc:creator>Mark Sanborn</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.nixtutor.com/?p=1126</guid>
		<description><![CDATA[Want to show someone across the internet something on your screen easily?  Dropbox makes it easy.
No related posts.]]></description>
			<content:encoded><![CDATA[<p>If you already have Dropbox you already know that it has a Public folder where you can save files for everyone to download.  If you are using the GUI version of Dropbox you can even right click on the file and get a public link to hand out.  Although this works great, we can automate this process and make it easier.</p>
<h4>Requirements</h4>
<ul>
<li><a href="http://www.getdropbox.com/">Dropbox</a></li>
<li>scrot &#8211; Screenshot utility</li>
<li>gqview &#8211; To optionally preview the screenshot</li>
<li>xclip &#8211; To automatically copy the url into the clipboard</li>
</ul>
<h2>Installing</h2>
<p>You know the drill, grab your package manager and install a few things.</p>
<div class="term">sudo apt-get install scrot gqview xclip</div>
<p>Create a file named, &#8216;<strong>screenshot.sh</strong>&#8216; and add the following:</p>
<pre name="code" class="python">#! /bin/sh

# Run this and it will take a screenshot of your desktop and optionally show it to you for confirmation
# Make sure you set the shotsdir to your dropbox public dir

shotsdir=$HOME/Dropbox/Public/shots
dropboxid="INSERTYOURIDHERE"
dropboxURL="http://dl.getdropbox.com/u/$dropboxid"
delay=5 # set to 0 for no delay

file=$shotsdir/shot-`date +%Y-%m-%d-%H-%M-%S`.png
mkdir -p $shotsdir
scrot -d $delay $* $file
if xmessage -buttons "Yes:0,Nah:1" -default "upload" "Want to preview your image?"
then
    gqview $file
fi
    echo -n "$dropboxURL/shots/"`basename $file` | xclip -i</pre>
<p><em>Note: This script is based on a similar one by <a href="http://www.reddit.com/user/micah">micah</a> on <a href="http://www.reddit.com">reddit</a>.</em></p>
<p>If your Dropbox folder is not in the default path you will need to change &#8216;<strong>shotsdir</strong>&#8216;.  Also, change the dropboxid variable to match your Dropbox id.  You can find your id buy right clicking on a file in the public folder and selecting <strong>Copy Public Link</strong>.</p>
<p>You can also change the &#8216;<strong>delay</strong>&#8216; variable if you want to have a delay before the screenshot is taken.  This will allow you to move windows around before the shot is taken.</p>
<p>The real beauty lies in the fact that the script will automatically put the public url in your clipboard.  To paste it to a friend simply middle click!</p>
<h2>Make an alias</h2>
<p>Now it would be nice not to have to change directories and type in &#8216;<strong>sh screenshot.sh</strong>&#8216; all the time.</p>
<p>We can set up a bash alias by editing, &#8216;<strong>~/.bashrc</strong>&#8216; and add the following line:</p>
<div class="term">alias ds=&#8217;sh /path/to/screenshot.sh&#8217;</div>
<p>Now you can drop screenshots simply by typing &#8216;<strong>ds</strong>&#8216; and hitting enter.</p>
<p>Of course you can pick any alias that fits your fancy. <img src='http://www.nixtutor.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/4tlmm-OND7PhuQwi320CSf9YjUg/0/da"><img src="http://feedads.g.doubleclick.net/~a/4tlmm-OND7PhuQwi320CSf9YjUg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/4tlmm-OND7PhuQwi320CSf9YjUg/1/da"><img src="http://feedads.g.doubleclick.net/~a/4tlmm-OND7PhuQwi320CSf9YjUg/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.nixtutor.com/linux/automatically-take-a-screenshot-and-make-it-public-using-dropbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an in-house Dropbox: Phase 1</title>
		<link>http://www.nixtutor.com/linux/creating-an-in-house-dropbox-phase-1/</link>
		<comments>http://www.nixtutor.com/linux/creating-an-in-house-dropbox-phase-1/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 11:00:22 +0000</pubDate>
		<dc:creator>Mark Sanborn</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.nixtutor.com/?p=1103</guid>
		<description><![CDATA[In this article we try to mimic the great <a href="http://www.getdropbox.com/">Dropbox</a>.  This part of the series deals with setting up basic file synchronization in Linux.
No related posts.]]></description>
			<content:encoded><![CDATA[<h2>Create a Central Repository</h2>
<p>Create a folder on a large hard drive or raid your main computer/server</p>
<p>For example:</p>
<div class="term">mkdir /meda/drobo/inhouseDropbox</div>
<p>On the repository machine install Unison</p>
<div class="term">sudo apt-get install unison</div>
<p>On the local machine connect via SSH and test that the install went ok</p>
<div class="term">ssh yourhostname unison -version</div>
<p>You should see something like, &#8220;<strong>unison version 2.27.57</strong>&#8220;.</p>
<p>Create a file in your repository directory:</p>
<div class="term">&gt; test.txt</div>
<h2>Install Unison on the Local Machine</h2>
<p>For a Debian based system do:</p>
<div class="term">sudo apt-get install unison</div>
<p>Make a folder in your home directory or wherever you want:</p>
<div class="term">mkdir /home/nixtutor/inhouseDropbox</div>
<p>Then run Unison:</p>
<div class="term">unison inhouseDropbox/ ssh://nixtutor//media/drobo/inhouseDropbox</div>
<p>Note the double slash after the hostname.  This is used to indicate an absolute path</p>
<p>You will be greeted with a message saying that this is the first time it has detected changes go ahead and hit the <strong>space bar</strong>.</p>
<p>Press <strong>y</strong> to confirm the &#8220;conflict&#8221; and transfer the files.  This should only happen the first time you setup a new directory.</p>
<h2>Setup Unison</h2>
<p>Create a <strong>inhouseDropbox.prf</strong> file and stick it in &#8216;<strong>/home/youruser/.unison</strong>&#8216;.</p>
<p>If should look something like:</p>
<pre>root = /home/youruser/inhouseDropbox
root = ssh://youruser@yourhost//media/drobo/inhouseDropbox

force = newer
times = true
batch = true</pre>
<p>Now we have automated preferences and just need to get rid of the password prompt for SSH.  The most common method of this is making a key file.</p>
<h4>Making a key</h4>
<p>On the local machine do <strong>ssh-keygen</strong>.<br />
Then scp the .pub file and append it to ~/.ssh/authorized_keys file on the remote computer.<br />
If you need additional help on how to make SSH keys see, <a href="http://www.debianhelp.org/node/1198">Setting Up SSH Keys</a></p>
<h2>Automating it</h2>
<p>Running Unison by hand doesn&#8217;t do us much good.  Let&#8217;s make Cron run it every two minutes or so.</p>
<div class="term">crontab -e</div>
<p>Then add the following line:</p>
<div class="term">*/2 * * * * /usr/bin/unison inhouseDropbox &gt; /dev/null</div>
<p>Then save the file.</p>
<p>To test it go ahead and drop another file in the folder and wait a few minutes.  The changes should propagate to the central repository.</p>
<h2>Troubleshooting</h2>
<p>Use</p>
<div class="term">tail -f /var/log/crond</div>
<p>To see if cron is running the job.</p>
<p>You can also append, <strong>&gt;&gt; /home/youruser/log.txt 2&gt;&amp;1</strong> instead of <strong>&gt; /dev/null</strong> to output all errors and regular messages to a log file in your home directory.</p>
<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/iikxROho8lWe-wQIICjyXRoaGsU/0/da"><img src="http://feedads.g.doubleclick.net/~a/iikxROho8lWe-wQIICjyXRoaGsU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/iikxROho8lWe-wQIICjyXRoaGsU/1/da"><img src="http://feedads.g.doubleclick.net/~a/iikxROho8lWe-wQIICjyXRoaGsU/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.nixtutor.com/linux/creating-an-in-house-dropbox-phase-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Rsync</title>
		<link>http://www.nixtutor.com/linux/using-rsync/</link>
		<comments>http://www.nixtutor.com/linux/using-rsync/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 11:00:24 +0000</pubDate>
		<dc:creator>Mark Sanborn</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.nixtutor.com/?p=1083</guid>
		<description><![CDATA[Rsync is one of the best tools can you can carry around in your tool belt.  Learn how to use the defacto standard backup and syncing application, rsync.
No related posts.]]></description>
			<content:encoded><![CDATA[<h2>What is rsync?</h2>
<p>Rysnc helps you transfer data from one location to another in an efficient manner.  It is one of those tools that you learn to use and wonder how you lived without it.  Rsync is the de facto standard in backup solutions because of its flexibility and power.</p>
<p>Rsync checks each file and transfers only what has changed.  What does this mean exactly?  Rsync will actually look and see what in the file has changed and upload only the part of the file that has changed.  Unlike ftp and other transfer solutions rsync doesn&#8217;t simply re-upload the entire file.</p>
<p>The difference in the files are then compressed (an optionally encrypted through ssh) then sent so the transfer uses the minimal amount of bandwidth.  Rsync is often used by <a href="http://aws.amazon.com/s3/">Amazon S3</a> users as they must pay for bandwidth.  When you are paying bandwidth bit by bit you can&#8217;t afford anything but rsync.</p>
<h2>Rsync is Efficient but What Else Can it Do?</h2>
<p>As you can probably tell by the name rsync is really good at syncing files across a network.  If a file has changed it can detect the change and transfer only that change.  This makes rsync a perfect candidate for doing incremental backups or mirroring a website.</p>
<p>For example to mirror one folder to another you could do:</p>
<div class="term">rsync –av /path/to/source /home/nixtutor/rsync/daily</div>
<p>You can also use the same technique to sync from one computer to another:</p>
<div class="term">rsync –av /path/to/source user@nixutor.com:/home/nixtutor/rsync/daily</div>
<p>By default this will only upload new files and changes but not delete or remove files that no longer exist.  To do this you can add the <strong>&#8211;delete</strong> flag.  This is rsync&#8217;s way of protecting yourself from mirroring a blank directory.</p>
<div class="term">rsync –av &#8211;delete /path/to/source user@nixutor.com:/home/nixtutor/rsync/daily</div>
<h4>Want to Sync Specific Files?</h4>
<p>In this example we only sync <strong>.iso</strong> files.</p>
<div class="term">rsync -zrv &#8211;include=&#8221;*.iso&#8221; host:/home/nixtutor /home/</div>
<h2>Things to Keep in Mind</h2>
<ul>
<li>Rsync is powerful but unforgiving</li>
<li>Rsync follows the unix methodology, do one thing and do it well.  Thus it doesn&#8217;t provide encryption only efficient file transferring.  Run rsync through SSH if you need encryption.</li>
<li>Rsync will not delete files that have been removed unless you supply the &#8211;delete flag.</li>
<li>Windows doesn&#8217;t keep file modification times to better than two seconds. Use the <strong>&#8211;modify-window=2</strong> option to get around this when syncing to Windows file shares.</li>
</ul>
<p>Most backup senarios can be done with rsync and cron.  For an example on how to create a daily weekly backup scheme check out, <a href="http://www.marksanborn.net/howto/use-rsync-for-daily-weekly-and-full-monthly-backups/">Use Rsync for Daily, Weekly and Full Monthly Backups</a>.</p>
<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/VYeSAfDyj8r5rMGsxt_bXSfRjD0/0/da"><img src="http://feedads.g.doubleclick.net/~a/VYeSAfDyj8r5rMGsxt_bXSfRjD0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/VYeSAfDyj8r5rMGsxt_bXSfRjD0/1/da"><img src="http://feedads.g.doubleclick.net/~a/VYeSAfDyj8r5rMGsxt_bXSfRjD0/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.nixtutor.com/linux/using-rsync/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>7 Tasks You Shouldn’t Use a GUI For</title>
		<link>http://www.nixtutor.com/linux/7-tasks-you-shouldnt-use-a-gui-for/</link>
		<comments>http://www.nixtutor.com/linux/7-tasks-you-shouldnt-use-a-gui-for/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 11:00:27 +0000</pubDate>
		<dc:creator>Mark Sanborn</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.nixtutor.com/?p=1061</guid>
		<description><![CDATA[Sometimes the GUI is just too slow.  Learn how to resize images, add drop shadows, splice mp3s, clone hard drives and more with the command line.
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Here are a few tasks that you might want to consider using the command line for.</p>
<h2>1. Resizing images</h2>
<p>Unless you are doing some sort of cropping there is no reason to load up Photoshop or the Gimp.  A simple command will usually suffice for almost all your image resizing needs.</p>
<div class="term">convert -resize 300 image.jpg image-small.jpg</div>
<p>If you finding yourself doing lots of image resizing during the day, this command could potentially save you a LOT of time.  You can even do mass image resizing.</p>
<h2>2. Adding a Drop Shadow to an Image</h2>
<p>I found myself spending a ton of time adding drop shadows to images.  Using a simple command I was able to create drop shadows in seconds.</p>
<p><img src="http://www.nixtutor.com/wp-content/uploads/2009/07/screenshot-suse.jpg" alt="suse screenshot" /></p>
<div class="term">convert screenshot.jpg \( +clone -background black -shadow 60&#215;5+0+5 \) +swap -background white -layers merge +repage shadow.jpg</div>
<p><em>Note: You must have <a href="http://www.imagemagick.org/script/index.php">Imagemagick</a> installed for this command to work.  Debian/Ubuntu users can use <a href="apt:imagemagick">apt-get install imagemagick</a>.</em></p>
<p><img src="http://www.nixtutor.com/wp-content/uploads/2009/07/shadow.png" alt="screenshot dropshadow" /></p>
<p>Obviously, I don&#8217;t expect you to memorize this command.  To shorten it use an <a href="http://eriwen.com/productivity/aliases-and-functions/">alias</a>.</p>
<h2>3. Splice Together an MP3</h2>
<p>If you want <strong>simple</strong> MP3 splicing this command has your back:</p>
<div class="term">cat 1.mp3 2.mp3 &gt; combined.mp3</div>
<h2>4. Clone a Hard Drive</h2>
<p>DD is one the most simplistic and powerful image applications out there.</p>
<div class="term">dd if=/dev/hda of=/dev/hdb</div>
<h2>5. Burn an ISO to a CD</h2>
<p>Why open up K3B or some other program just to burn an ISO?  Map this command to an alias and get burning.</p>
<div class="term"> cdrecord -v speed=8 dev=0,0,0 name_of_iso_file.iso</div>
<p><em>Note: You need to get the info for the &#8216;dev=&#8217; part by running &#8216;cdrecord -scanbus&#8217;</em></p>
<h2>6. Video Conversions</h2>
<p>Let&#8217;s say you want to convert an AVI to an Mpeg file:</p>
<div class="term">ffmpeg -i video_origine.avi video_finale.mpg</div>
<p>Or convert an Mpeg to AVI:</p>
<div class="term">ffmpeg -i video_origine.mpg video_finale.avi</div>
<p>There are <a href="http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs">all sorts of things you can do with ffmpeg</a>.</p>
<h2>7. Replace Words in a Text File</h2>
<p>No need to open up a GUI text editor when you have sed.</p>
<p>This command from <a href="http://eriwen.com/tools/get-sed-savvy-1/">Eric&#8217;s Wendelin&#8217;s blog</a> will replace all instances of a color in CSS with another one.</p>
<div class="term">sed &#8216;s/#FF0000/#0000FF/g&#8217; main.css</div>
<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/Hv8ly4vDceoQ_xVNLbVSUGQrgPw/0/da"><img src="http://feedads.g.doubleclick.net/~a/Hv8ly4vDceoQ_xVNLbVSUGQrgPw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Hv8ly4vDceoQ_xVNLbVSUGQrgPw/1/da"><img src="http://feedads.g.doubleclick.net/~a/Hv8ly4vDceoQ_xVNLbVSUGQrgPw/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.nixtutor.com/linux/7-tasks-you-shouldnt-use-a-gui-for/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
		<item>
		<title>Linux Shutdown Management</title>
		<link>http://www.nixtutor.com/linux/linux-shutdown-management/</link>
		<comments>http://www.nixtutor.com/linux/linux-shutdown-management/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 11:00:26 +0000</pubDate>
		<dc:creator>Mark Sanborn</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.nixtutor.com/?p=1031</guid>
		<description><![CDATA[Everything you need to know about shutting down and rebooting Linux from the command line.
No related posts.]]></description>
			<content:encoded><![CDATA[<h2>The Commands</h2>
<p>Here are a few example of all the ways we can shutdown and reboot on a nix machine.</p>
<h4>Power off the Machine Now</h4>
<div class="term">sudo halt</div>
<h4>Shutdown 10 Minutes From Now</h4>
<div class="term">sudo shutdown -h +10 &#8216;Shutting down in 5 minutes!&#8217;</div>
<h4>Reboot at 11pm</h4>
<div class="term">sudo shutdown -r 23:00</div>
<h4>Cancel That</h4>
<p>If you decide you don&#8217;t need to shutdown after all you can issue a cancel command like this:</p>
<div class="term">sudo shutdown -c</div>
<h4>Give a Shutdown Warning  Without Actually Shutting Down</h4>
<div class="term">sudo shutdown -k now &#8216;Hey I am going to the server room and this computer might get unplugged.  Please save your work.&#8217;</div>
<h4>Waking your Computer up</h4>
<p><a href="http://blog.crowdway.com/2008/05/23/make-your-pc-wake-you-up/">David, from crowdway blog, posted a command</a> that tells your computer to wake up 5 minutes from now.  To try enter the command and shut your computer down.</p>
<div class="term">echo &#8220;+00-00-00 00:05:00&#8243; &gt; /proc/acpi/alarm</div>
<h4>Reboot Daily with Cron</h4>
<p>Open up cron as root with, &#8216;<strong>sudo crontab -e</strong>&#8216; and add the following line to reboot each night at 11:55pm.</p>
<div class="term">55 23 * * * reboot</div>
<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/iEVq7Kl5UJKo7C6HU7eUiJUgQHQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/iEVq7Kl5UJKo7C6HU7eUiJUgQHQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/iEVq7Kl5UJKo7C6HU7eUiJUgQHQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/iEVq7Kl5UJKo7C6HU7eUiJUgQHQ/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.nixtutor.com/linux/linux-shutdown-management/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sending Mail Through Gmail with Perl</title>
		<link>http://www.nixtutor.com/linux/sending-mail-through-gmail-with-perl/</link>
		<comments>http://www.nixtutor.com/linux/sending-mail-through-gmail-with-perl/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 11:00:22 +0000</pubDate>
		<dc:creator>Mark Sanborn</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.nixtutor.com/?p=990</guid>
		<description><![CDATA[Discover how to send mail through Gmail with perl.
No related posts.]]></description>
			<content:encoded><![CDATA[<p>We talked about some of the <a href="http://www.nixtutor.com/linux/the-benefits-o…y-email-server/">benefits</a> of <a href="http://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/">setting up an email server in Linux</a> and how you can <a href="http://www.nixtutor.com/linux/send-mail-through-gmail-with-python/">use python to send email</a>.  Now we are going to look at how you can send email from Perl.</p>
<h2>The Code</h2>
<pre name="code" class="python">use Net::SMTP::TLS;
my $mailer = new Net::SMTP::TLS(
	'smtp.gmail.com',
	Hello   =>      'smtp.gmail.com',
	Port    =>      587,
	User    =>      'username',
	Password=>      'password');
$mailer->mail('from@domain.com');
$mailer->to('to@domain.com');
$mailer->data;
$mailer->datasend("Sent from perl!");
$mailer->dataend;
$mailer->quit;</pre>
<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/WtZKt9r9orSowasF-oTUsVaj54M/0/da"><img src="http://feedads.g.doubleclick.net/~a/WtZKt9r9orSowasF-oTUsVaj54M/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/WtZKt9r9orSowasF-oTUsVaj54M/1/da"><img src="http://feedads.g.doubleclick.net/~a/WtZKt9r9orSowasF-oTUsVaj54M/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.nixtutor.com/linux/sending-mail-through-gmail-with-perl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Sending Email Alerts Through Cron</title>
		<link>http://www.nixtutor.com/linux/sending-email-alerts-through-cron/</link>
		<comments>http://www.nixtutor.com/linux/sending-email-alerts-through-cron/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 11:00:54 +0000</pubDate>
		<dc:creator>Mark Sanborn</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.nixtutor.com/?p=996</guid>
		<description><![CDATA[After you have an email server configured it is time to set the MAILTO variable and start getting email alerts about your scheduled cron tasks.
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Cron is the Linux task scheduler that is responsible for making sure scripts run at their specified times.  Cron is often used for things like, log rotation, backup scripts, updating file indexes, and running custom scripts.  In the event a task runs into problems or errors Cron generally tries to email the local administrator of the machine.  This means it tries to send an email to itself instead of an &#8220;internet accessible&#8221; email address like, &#8216;user@gmail.com&#8217;.</p>
<p>We can change this default behavior by changing the <strong>MAILTO</strong> variable.<br />
<em><br />
Note: This will not work if you have not <a href="http://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/">setup an email server</a>.</em></p>
<h2>Setting the MAILTO variable</h2>
<p>Cron relies on a simple text file to schedule commands.  To edit this file just issue the <strong>crontab</strong> command:</p>
<div class="term">crontab -e</div>
<p>To change the <strong>MAILTO</strong> variable just add &#8216;<b>MAILTO=username@domain.com</b>&#8216; into the crontab file.</p>
<p>It should look something like this:</p>
<p><img src="http://www.nixtutor.com/wp-content/uploads/2009/07/mailto-cron.png" alt="set mailto in cron" /></p>
<h2>Specify Email for Each Script</h2>
<p>If we don&#8217;t want all output to go to the same email address we can specify the output of a particular script to go to a different email address:</p>
<div class="term">59 */6 * * * script.sh | mail -s &#8220;Subject of Mail&#8221; someother@address.com</div>
<h2>Email Alerts for All but One</h2>
<p>If you have a specific script in your crontab that you don&#8217;t want output or errors emailed to you, simply add, &#8216;<strong>&gt;/dev/null 2>&#038;1</strong>&#8216; to the end of the command.</p>
<div class="term">59 */6 * * * script.sh >/dev/null 2>&#038;1</div>
<p>To find out what else you can do with cron check out, <a href="http://www.marksanborn.net/linux/learning-cron-by-example/">Learning Cron by Example</a>.</p>
<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/--E3qo8ikLM4M7x-XyE_jE4ttvE/0/da"><img src="http://feedads.g.doubleclick.net/~a/--E3qo8ikLM4M7x-XyE_jE4ttvE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/--E3qo8ikLM4M7x-XyE_jE4ttvE/1/da"><img src="http://feedads.g.doubleclick.net/~a/--E3qo8ikLM4M7x-XyE_jE4ttvE/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.nixtutor.com/linux/sending-email-alerts-through-cron/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Benefits of Setting up sSMTP or any Email Server</title>
		<link>http://www.nixtutor.com/linux/the-benefits-of-setting-up-ssmtp-or-any-email-server/</link>
		<comments>http://www.nixtutor.com/linux/the-benefits-of-setting-up-ssmtp-or-any-email-server/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 11:00:10 +0000</pubDate>
		<dc:creator>Mark Sanborn</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.nixtutor.com/?p=967</guid>
		<description><![CDATA[One of the biggest reasons for installing an email server on a Nix machine is the ability to use scripts to send alerts in the case of security concerns, hardware failure, or when certain mission critical tasks are completed successfully.
No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/">Setting up an email server on Nix machine</a> is invaluable to keep an eye on multiple machines.  Lets face it, often times Nix machines run so well that we sometimes forget to login and check on them every once and awhile.  Why not make them check on their selves by scripting them to email you when they need some maintenance love?</p>
<p>We can have our Nix boxes report:</p>
<ul>
<li>Security concerns</li>
<li>Hardware failure</li>
<li>When mission critical tasks are completed successfully</li>
<li>When backups fail</li>
<li>When RAID fails</li>
<li>When temperature is dangerously high</li>
<li>When services are unavailable</li>
</ul>
<h2>Send Email Alert on Root Login</h2>
<p>Certain machines require only periodic root access.  This is often the case on shared servers.  You can setup an email alert that will immediately notify you that someone has accessed the root account.</p>
<p>Login as root and edit the file, &#8216;<strong>~/.bash_profile&#8217;</strong>.  Near the bottom add this:</p>
<div class="term">echo -e &#8220;Subject: Root Access\n\nALERT &#8211; Root Shell Access on: `date`, `who`\n&#8221; | ssmtp user@domain.com</div>
<p>Now to test it, log out of root and then log back on as root.  You should now get an alert that someone has logged in as root.  This script shows the time and user.  You can adjust the information accordingly depending on how detailed you want it.</p>
<p>Example:</p>
<pre>ALERT - Root Shell Access on: Tue Jun 30 20:06:40 MDT 2009,
nixtutor     pts/0        2009-06-30 19:47 (NixTutor)</pre>
<p>This should work as long as your root account uses bash and you have <a href="http://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/">ssmtp setup correctly</a>.</p>
<h2>Send Email Alert on Hardware Failure</h2>
<p>Linux has some great hardware monitoring tools to give us an overall health status of our system.  <a href="http://www.lm-sensors.org/">Lm-sensors</a> can report things like, processor temperature, fan speed, and voltages of the motherboard and other components.  <a href="http://smartmontools.sourceforge.net/">Smartmontools</a> can give us information for S.M.A.R.T compatible hard drives that could warn us before hard drive failure and data disaster occurs.</p>
<p>Using these tools and a little bit of knowledge of Bash scripting or other scripting languages like, python, perl, or ruby we can easily create automated system health checks that can report back in the event of failure via email or TXT message.</p>
<h2>Send Email Alert to Cell Phone</h2>
<p>There may be a time where an error on a server is so critical that it needs to be sent directly to your phone.  A lot of cell phone carriers have an <a href="http://www.marksanborn.net/howto/how-to-send-a-txt-message-through-email/">SMS email gateway</a> that will forward emails to the cell phone as a text message.  This allows us to use sSMTP (or any email server) to send out text messages directly to our phones.</p>
<p>For example if I wanted to send a text message to a phone on the Verizon network I would use, <strong>1234567891@vtext.com</strong>.</p>
<p>For a complete listing of SMS gateways you can see this article, <a href="http://www.marksanborn.net/howto/how-to-send-a-txt-message-through-email/">How to: Send a TXT Message Through Email</a>.</p>
<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/aAC3Exi6ptmwiTxq3WkX7HIPkcM/0/da"><img src="http://feedads.g.doubleclick.net/~a/aAC3Exi6ptmwiTxq3WkX7HIPkcM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/aAC3Exi6ptmwiTxq3WkX7HIPkcM/1/da"><img src="http://feedads.g.doubleclick.net/~a/aAC3Exi6ptmwiTxq3WkX7HIPkcM/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.nixtutor.com/linux/the-benefits-of-setting-up-ssmtp-or-any-email-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Send Mail Through Gmail with Python</title>
		<link>http://www.nixtutor.com/linux/send-mail-through-gmail-with-python/</link>
		<comments>http://www.nixtutor.com/linux/send-mail-through-gmail-with-python/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 11:00:47 +0000</pubDate>
		<dc:creator>Mark Sanborn</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.nixtutor.com/?p=946</guid>
		<description><![CDATA[Python is a great scripting language for Linux and it is often used to automate tasks or check on overall system health.  Discover how to send emails through Gmail with Python.
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Good system admins get to know scripting languages well and sometimes use them for all kinds of purposes, from scripts that do backups to complex automated tasks.  Often times it would be nice to get an email notification when the script finished or completed OK.  Cron does a good job of sending emails when scripts run into errors or problems, but sometimes it is necessary to get custom email messages sent from the script itself.  Python makes sending email alerts a breeze.</p>
<h2>The Code</h2>
<pre name="code" class="python">import smtplib

fromaddr = 'fromuser@gmail.com'
toaddrs  = 'touser@gmail.com'
msg = 'There was a terrible error that occured and I wanted you to know!'

# Credentials (if needed)
username = 'username'
password = 'password'

# The actual mail send
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()</pre>
<h2>What Now?</h2>
<p>You will want to use this with an already existing script or a script where you want to add email alerts.  For example:</p>
<pre name="code" class="python">
# A big task
...
if task.completedOk():
     # Insert email code here, explaining that
     # the task is done and some details about it
</pre>
<p>Or perhaps you wanted Python to send you an email if the server room gets too hot:</p>
<pre name="code" class="python">
# Get temp
...
if temperature > 70:
     # Insert email code here
</pre>
<p>No related posts.</p>
<p><a href="http://feedads.g.doubleclick.net/~a/a4YKFgJ5TNaARpU1WA6JphUtgBw/0/da"><img src="http://feedads.g.doubleclick.net/~a/a4YKFgJ5TNaARpU1WA6JphUtgBw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/a4YKFgJ5TNaARpU1WA6JphUtgBw/1/da"><img src="http://feedads.g.doubleclick.net/~a/a4YKFgJ5TNaARpU1WA6JphUtgBw/1/di" border="0" ismap="true"></img></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.nixtutor.com/linux/send-mail-through-gmail-with-python/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

