<?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>The Tech Tutorial &#187; Tutorial</title>
	<atom:link href="http://www.the-tech-tutorial.com/?feed=rss2&#038;cat=11" rel="self" type="application/rss+xml" />
	<link>http://www.the-tech-tutorial.com</link>
	<description>Just a blog of free technology tutorials</description>
	<lastBuildDate>Tue, 04 Dec 2012 15:43:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Ruby On Rails, dynamic table&#8217;s &amp; add button using nested_attributes</title>
		<link>http://www.the-tech-tutorial.com/?p=1939</link>
		<comments>http://www.the-tech-tutorial.com/?p=1939#comments</comments>
		<pubDate>Wed, 26 Sep 2012 13:37:53 +0000</pubDate>
		<dc:creator>Tyler Allen</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[RoR]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://www.the-tech-tutorial.com/?p=1939</guid>
		<description><![CDATA[So here’s the problem, you want to create several items that belong to one item, normally you would just the the has_many and belongs_to (OneToMany) relation in rails. Using this model you create the primary model (such as purchase order) then create several sub items (such as item) and attach them to the primary model. [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2012/09/Top.png"><img class="alignleft  wp-image-1942" title="Top" src="http://www.the-tech-tutorial.com/wp-content/uploads/2012/09/Top.png" alt="" width="140" height="89" /></a>So here’s the problem, you want to create several items that belong to one item, normally you would just the the has_many and belongs_to (OneToMany) relation in rails. Using this model you create the primary model (such as purchase order) then create several sub items (such as item) and attach them to the primary model. The problem with this is its time consuming and does not always make sense to do things this way, take the Purchase order and Items scenario, it makes much more sense to create the Purchase order and assciated Items in the same form. This is possible in rails uing nested_attributes.</p>
<p style="text-align: left;"><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2012/09/Items.jpg"><img class="aligncenter size-full wp-image-1941" title="Items" src="http://www.the-tech-tutorial.com/wp-content/uploads/2012/09/Items.jpg" alt="" width="450" height="195" /></a></p>
<p><span id="more-1939"></span></p>
<p style="text-align: left;">For this tutorial I&#8217;m going to be adding the sub-model Items to the Primary model Purchase Order, this will allow the Purchase order to have several items attached to it. To start with I created a simple Purchase order scaffold</p>
<pre class="brush:ruby">
Rails generate scaffold PurchaseOrder name:string
</pre>
<p>Now we need to add create the Items model:</p>
<pre class="brush:ruby">
Rails generate scaffold Item part_no:string description:string qty:string price:string
</pre>
<p>After we have created both models its time for the nested_attributes asscoitain, this will allow us to creat several items at the same time and the purchase order, to do this edit your Purchase order model to look like this:</p>
<p><strong>&#8220;app/models/purchase.rb&#8221;</strong></p>
<pre class="brush:ruby">
class Purchase < ActiveRecord::Base
  has_many :items
  
  accepts_nested_attributes_for :items, :allow_destroy => true
end
</pre>
<p>Now we need to edit the controller to manage the nested_attributes and dynamic table, add the folowing code the the new, create and update actions in the Purchase controller<br />
<center><br />
<script type="text/javascript"><!--
google_ad_client = "ca-pub-2094089617852812";
/* 2011 Bottom */
google_ad_slot = "5825267234";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center><br />
<strong>&#8220;app/controllers/purchases_controller.rb&#8221;</strong></p>
<pre class="brush:ruby">
def new
@purchase = Purchase.new</code>

@purchase.items.build

respond_to do |format|
format.html # new.html.erb
format.json { render json: @purchase }
end
end

def create
@purchase = Purchase.new(params[:purchase])

if params[:add_item]=="Add item"
@purchase.items.build
render :action =&gt; 'edit'
else
respond_to do |format|
if @purchase.update_attributes(params[:purchase])
format.html { redirect_to @purchase, notice: 'Purchase was successfully updated.' }
format.json { head <img src='http://www.the-tech-tutorial.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> k }
else
format.html { render action: "edit" }
format.json { render json: @purchase.errors, status: :unprocessable_entity }
end
end

def update
@purchase = Purchase.find(params[:id])
if params[:add_item]=="Add item"
@purchase.items.build
render :action =&gt; 'edit'
else
respond_to do |format|
if @purchase.update_attributes(params[:purchase])
format.html { redirect_to @purchase, notice: 'Purchase was successfully updated.' }
format.json { head <img src='http://www.the-tech-tutorial.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> k }
else
format.html { render action: "edit" }
format.json { render json: @purchase.errors, status: :unprocessable_entity }
end
end
end
end
</pre>
<p>Now add the following to the form view:</p>
<p><strong>&#8220;app/views/purchases/_form.html.erb&#8221;</strong></p>
<pre class="brush:ruby">
       <%= f.fields_for :items do |builder| %>
        <tr>
        <td><%= f.text_field :part_no, :style=>"width:70px;", :disabled=>@disabled %></td>
        <td><%= f.text_field :description, :disabled=>@disabled %></td>
        <td><%= f.text_field :quantity, :style=>"width:30px;", :disabled=>@disabled %></td>
        <td><%= f.text_field :price,:style=>"width:50px;", :disabled=>@disabled %></td>
        </tr>
     <% end %>
</pre>
<p>No restart your application and navigate to your Purchases model and create a new item <em>(http://127.0.0.1:3000/purchases/new)</em>, now you will see your form with a dynamic sub from where you can create severl of the sub model, i.e. Items. </p>
<p>If you have an any problems or comments please leave them below</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="standard" count="" href="http://www.the-tech-tutorial.com/?p=1939"></g:plusone></div>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=Ruby+On+Rails%2C+dynamic+table%27s+%26+add+button+using+nested_attributes&amp;link=http://www.the-tech-tutorial.com/?p=1939&amp;notes=So%20here%E2%80%99s%20the%20problem%2C%20you%20want%20to%20create%20several%20items%20that%20belong%20to%20one%20item%2C%20normally%20you%20would%20just%20the%20the%20has_many%20and%20belongs_to%20%28OneToMany%29%20relation%20in%20rails.%20Using%20this%20model%20you%20create%20the%20primary%20model%20%28such%20as%20purchase%20order%29%20then%20create%20several%20sub%20items%20%28such%20as%20item%29%20and%20attach%20the&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=Ruby+On+Rails%2C+dynamic+table%27s+%26+add+button+using+nested_attributes&amp;link=http://www.the-tech-tutorial.com/?p=1939&amp;notes=So%20here%E2%80%99s%20the%20problem%2C%20you%20want%20to%20create%20several%20items%20that%20belong%20to%20one%20item%2C%20normally%20you%20would%20just%20the%20the%20has_many%20and%20belongs_to%20%28OneToMany%29%20relation%20in%20rails.%20Using%20this%20model%20you%20create%20the%20primary%20model%20%28such%20as%20purchase%20order%29%20then%20create%20several%20sub%20items%20%28such%20as%20item%29%20and%20attach%20the&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.shareaholic.com/api/share/?title=Ruby+On+Rails%2C+dynamic+table%27s+%26+add+button+using+nested_attributes&amp;link=http://www.the-tech-tutorial.com/?p=1939&amp;notes=So%20here%E2%80%99s%20the%20problem%2C%20you%20want%20to%20create%20several%20items%20that%20belong%20to%20one%20item%2C%20normally%20you%20would%20just%20the%20the%20has_many%20and%20belongs_to%20%28OneToMany%29%20relation%20in%20rails.%20Using%20this%20model%20you%20create%20the%20primary%20model%20%28such%20as%20purchase%20order%29%20then%20create%20several%20sub%20items%20%28such%20as%20item%29%20and%20attach%20the&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=&amp;tags=&amp;ctype=" rel="nofollow" class="external" title=""></a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=Ruby+On+Rails%2C+dynamic+table%27s+%26+add+button+using+nested_attributes&amp;link=http://www.the-tech-tutorial.com/?p=1939&amp;notes=So%20here%E2%80%99s%20the%20problem%2C%20you%20want%20to%20create%20several%20items%20that%20belong%20to%20one%20item%2C%20normally%20you%20would%20just%20the%20the%20has_many%20and%20belongs_to%20%28OneToMany%29%20relation%20in%20rails.%20Using%20this%20model%20you%20create%20the%20primary%20model%20%28such%20as%20purchase%20order%29%20then%20create%20several%20sub%20items%20%28such%20as%20item%29%20and%20attach%20the&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=Ruby+On+Rails%2C+dynamic+table%27s+%26+add+button+using+nested_attributes&amp;link=http://www.the-tech-tutorial.com/?p=1939&amp;notes=So%20here%E2%80%99s%20the%20problem%2C%20you%20want%20to%20create%20several%20items%20that%20belong%20to%20one%20item%2C%20normally%20you%20would%20just%20the%20the%20has_many%20and%20belongs_to%20%28OneToMany%29%20relation%20in%20rails.%20Using%20this%20model%20you%20create%20the%20primary%20model%20%28such%20as%20purchase%20order%29%20then%20create%20several%20sub%20items%20%28such%20as%20item%29%20and%20attach%20the&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=Ruby+On+Rails%2C+dynamic+table%27s+%26+add+button+using+nested_attributes&amp;link=http://www.the-tech-tutorial.com/?p=1939&amp;notes=So%20here%E2%80%99s%20the%20problem%2C%20you%20want%20to%20create%20several%20items%20that%20belong%20to%20one%20item%2C%20normally%20you%20would%20just%20the%20the%20has_many%20and%20belongs_to%20%28OneToMany%29%20relation%20in%20rails.%20Using%20this%20model%20you%20create%20the%20primary%20model%20%28such%20as%20purchase%20order%29%20then%20create%20several%20sub%20items%20%28such%20as%20item%29%20and%20attach%20the&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.shareaholic.com/api/share/?title=Ruby+On+Rails%2C+dynamic+table%27s+%26+add+button+using+nested_attributes&amp;link=http://www.the-tech-tutorial.com/?p=1939&amp;notes=So%20here%E2%80%99s%20the%20problem%2C%20you%20want%20to%20create%20several%20items%20that%20belong%20to%20one%20item%2C%20normally%20you%20would%20just%20the%20the%20has_many%20and%20belongs_to%20%28OneToMany%29%20relation%20in%20rails.%20Using%20this%20model%20you%20create%20the%20primary%20model%20%28such%20as%20purchase%20order%29%20then%20create%20several%20sub%20items%20%28such%20as%20item%29%20and%20attach%20the&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=88&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="https://shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.the-tech-tutorial.com/?feed=rss2&#038;p=1939</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Ruby on Rails Ubuntu 12.04 using RVM and Ruby 1.9.3</title>
		<link>http://www.the-tech-tutorial.com/?p=1868</link>
		<comments>http://www.the-tech-tutorial.com/?p=1868#comments</comments>
		<pubDate>Mon, 21 Nov 2011 13:06:13 +0000</pubDate>
		<dc:creator>Tyler Allen</dc:creator>
				<category><![CDATA[Fix It]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[configure]]></category>
		<category><![CDATA[Easy]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Rails 3.1]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Ruby 1.9.2]]></category>
		<category><![CDATA[RVM]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Setup]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Ubuntu 11.10]]></category>

		<guid isPermaLink="false">http://www.the-tech-tutorial.com/?p=1868</guid>
		<description><![CDATA[Ruby Rails is a Web application framework created in 2004 intended as a rapid development web framework that runs the Ruby programing language. The latest version of the Ruby is &#8216;Ruby 1.9.2&#8216; and was realised in August 2011, it brings many new features and bug fixeses. The most signifiant changes are Block local variables, An [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/11/rails.png"><img class="alignleft size-full wp-image-1851" title="rails" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/11/rails.png" alt="" width="87" height="111" /></a><span><span>Ruby</span> <span>Rails</span></span> is a Web application framework created in 2004 intended as a rapid development web framework that runs the <span>Ruby</span> programing language. The latest version of the <span>Ruby</span> is &#8216;<span>Ruby 1.9.2</span>&#8216; and was realised in <span>August 2011</span>, it brings many new features and bug fixeses. The most signifiant changes are <a href="http://en.wikipedia.org/wiki/Local_variable" target="_blank">Block local variables</a>, An additional <a href="http://en.wikipedia.org/wiki/Anonymous_function" target="_blank">lambda</a> syntax, Per-string <a href="http://en.wikipedia.org/wiki/Character_encoding" target="_blank">character encodings</a> are supported and a new New socket API (<a href="http://en.wikipedia.org/wiki/IPv6" target="_blank">IPv6</a> support). You can find a great walkthrough of all the new features at <a href="http://rubyinside.com/19walkthrough/" target="_blank">Ruby Inside</a>. coinciding with the release of <span><span>Ruby</span> 1.9</span> is the <span>Rails 3.1</span> framework which requires <span>Ruby 1.8.7</span> or higher. <span><span>Ruby</span>on<span>Rails</span> 3.1</span> brings many new features, most notably: jQuery as default, HTTP Streaming, a new assets pipeline powered by <a href="https://github.com/sstephenson/sprockets/" target="_blank">Sprockets 2.0</a>. So this is all good stuff and I’m sure you want to be working with the latest version of Ruby and RubyonRails, especially if you setting up a new server.<span id="more-1868"></span></p>
<div style="width:350px; height:330px;background-image: url(http://www.the-tech-tutorial.com/wp-content/uploads/2011/03/add_back1.png); display: block; float: left; padding: 20px 25px 0px 30px;">
<script type="text/javascript"><!--
google_ad_client = "pub-2094089617852812";
/* 2011 In Text Box */
google_ad_slot = "1777411765";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>Well if your using Ubuntu you can setup <span>Ruby</span> and <span><span>Ruby</span>on<span>Rails</span></span> quickly using the supplied repository’s, a good tutorial for this can be <a href="http://www.the-tech-tutorial.com/?p=1801" target="_blank">found here</a>. However this is not recommended as the <span>Ubuntu</span> repositories are often out of date and if you install ruby or <span>rails</span> via the repository’s it can be pain to <span>upgrade</span>. So in this guide we are going to go through <span>installing <span>RVM</span></span> (this allows you to <span>install</span>, <span>change</span> and <span>upgrade</span> the installed <span>Ruby</span> version), <span>Ruby</span> <span>1.9.2</span></span> and <span><span>Rails</span> <span>3.1</span></span>. This Guide has been tested on <span>Ubuntu 11.10</span> however it should work on all versions of <span>Ubuntu</span> later then <span>Ubuntu 9.04</span>.</p>
<p>First of all you&#8217;ll need to install some packages that <span>Ruby</span>, <span>RVM</span> and <span><span>Ruby</span>On<span>Rails</span></span> will require later, the easiest way to do this is using the repositories so go to your terminal and type:</p>
<pre>sudo apt-get update
sudo apt-get install build-essential git-core curl libmysqlclient18 nodejs</pre>
<p>Now let’s install the latest version of <span>RVM</span> using <span>curl</span>:</p>
<pre>sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
umask g+w
source /etc/profile.d/rvm.sh 
</pre>
<p>Now you'll need to ask <span>RVM</span> if it needs any more programs and if so you'll need to install them to do this type:</p>
<pre>rvm requirements</pre>
<p>Two things could happen here if you see the following message saying you need to install '<span>rvm</span>', ignore this it and restart your terminal, this should fix the problem.</p>
<pre><span><span>The program <span>'rvm'</span> is currently <span>not <span>install</span>ed</span></span>.  You can install it by typing:
<span>sudo apt-get install ruby-rvm</span></span></pre>
<p>You should see something that looks like this <strong>after you restart your terminal</strong>:<br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/11/rvm_req.jpg"><img src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/11/rvm_req.jpg" alt="" title="rvm_req" width="641" height="355" class="aligncenter size-full wp-image-1885" /></a></p>
<p>This tells you which packages you need to install using <span>apt-get</span>, just copy and paste the apt-get section under "# For <span>Ruby</span>" and run using the sudo command, this should look something like this:</p>
<pre>
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
</pre>
<p>Now you just need to give the user account access to the rvm files, you do this with the following command substituting [user] for the user you wish to use</p>
<pre>
sudo chown -R [user]:[user] /usr/local/rvm
</pre>
<p>Before completing this step I would recomend restarting your console otherwise you may run into problems. Once you have installed all these packages its time to install <span>Ruby 1.9.3</span> herself. The following command will install <span>Ruby 1.9.3</span> using the <span>rmv</span> package. However this can take a few minutes <em>(15 in my case)</em> to install so I recommend getting a drink, or my favourite, a pizza <img src='http://www.the-tech-tutorial.com/wp-includes/images/smilies/icon_lol.gif' alt=':lol:' class='wp-smiley' />  .</p>
<pre>rvm install 1.9.3</pre>
<p>Once <span>ruby</span> is installed you should set <span><span>Ruby</span> <span>1.9.3</span></span> as your <span><span><span>default</span> <span>Ruby</span></span> version</span>, to do this enter:</p>
<pre>
source "/usr/local/rvm/scripts/rvm"
rvm --default use 1.9.3
</pre>
<p>You can test that <span>Ruby</span> is installed correctly and running at version <span>1.9.2</span> by typing</p>
<pre>ruby -v</pre>
<div style="width:350px; height:330px;background-image: url(http://www.the-tech-tutorial.com/wp-content/uploads/2011/03/add_back1.png); display: block; float: right; padding: 20px 25px 0px 30px;">
<script type="text/javascript"><!--
google_ad_client = "pub-2094089617852812";
/* 2011 In Text Box */
google_ad_slot = "1777411765";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>This should output something like "ruby 1.9.2p290.." showing you that <span>version 1.9.2p290</span> is installed and is now the default <span>Ruby</span> version. </p>
<p>The nice thing about <span>RVM</span> is you can use it to install any version of <span>Ruby</span> and switch between the versions your have installed, to do this just enter "rvm install [Version Number]" then "rvm --default use [Version Number", you can then use "rvm --default use" to change to any installed version.</p>
<p>Now that you have the latest version of ruby installed I’m sure you want to get the <span><span>latest version of <span><span>Rails</span> install</span></span>ed</span>, at the time of writing this tutorial that’s <span>Rails 3.1</span>. To install <span>Rails</span> we can use <span>GEM</span> which is installed along with <span>RVM</span> and <span>Ruby</span>, to install the latest version of <span>Rails</span> just type, <em>(this can take also take a while)</em>:</p>
<pre>gem install rails</pre>
<p>And that’s it you have now installed <span><span>RVM</span>, <span>Ruby 1.9.2</span> and <span>Rails 3.1</span> on <span>Ubuntu 11.10</span></span> configured to use <span>sqlite3<span>, you can now setup your new <span><span>Rails</span> package</span> with </p>
<pre>rails new [project name]</pre>
<p>Just as a final note, If you want to <span>use MySQL</span> instead of <span>sqlite3</span> you&#8217;ll need to enter the following</p>
<pre>
sudo apt-get install mysql-server
gem install <span>mysql2</span>
rails new [project name] -d mysql
</pre>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="standard" count="" href="http://www.the-tech-tutorial.com/?p=1868"></g:plusone></div>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+Ruby+on+Rails+Ubuntu+12.04+using+RVM+and+Ruby+1.9.3&amp;link=http://www.the-tech-tutorial.com/?p=1868&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework%20that%20runs%20the%20Ruby%20programing%20language.%20The%20latest%20version%20of%20the%20Ruby%20is%20%27Ruby%201.9.2%27%20and%20was%20realised%20in%20August%202011%2C%20it%20brings%20many%20new%20features%20and%20bug%20fixeses.%20The%20most%20signifiant%20changes%20are&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+Ruby+on+Rails+Ubuntu+12.04+using+RVM+and+Ruby+1.9.3&amp;link=http://www.the-tech-tutorial.com/?p=1868&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework%20that%20runs%20the%20Ruby%20programing%20language.%20The%20latest%20version%20of%20the%20Ruby%20is%20%27Ruby%201.9.2%27%20and%20was%20realised%20in%20August%202011%2C%20it%20brings%20many%20new%20features%20and%20bug%20fixeses.%20The%20most%20signifiant%20changes%20are&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+Ruby+on+Rails+Ubuntu+12.04+using+RVM+and+Ruby+1.9.3&amp;link=http://www.the-tech-tutorial.com/?p=1868&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework%20that%20runs%20the%20Ruby%20programing%20language.%20The%20latest%20version%20of%20the%20Ruby%20is%20%27Ruby%201.9.2%27%20and%20was%20realised%20in%20August%202011%2C%20it%20brings%20many%20new%20features%20and%20bug%20fixeses.%20The%20most%20signifiant%20changes%20are&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=&amp;tags=&amp;ctype=" rel="nofollow" class="external" title=""></a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+Ruby+on+Rails+Ubuntu+12.04+using+RVM+and+Ruby+1.9.3&amp;link=http://www.the-tech-tutorial.com/?p=1868&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework%20that%20runs%20the%20Ruby%20programing%20language.%20The%20latest%20version%20of%20the%20Ruby%20is%20%27Ruby%201.9.2%27%20and%20was%20realised%20in%20August%202011%2C%20it%20brings%20many%20new%20features%20and%20bug%20fixeses.%20The%20most%20signifiant%20changes%20are&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+Ruby+on+Rails+Ubuntu+12.04+using+RVM+and+Ruby+1.9.3&amp;link=http://www.the-tech-tutorial.com/?p=1868&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework%20that%20runs%20the%20Ruby%20programing%20language.%20The%20latest%20version%20of%20the%20Ruby%20is%20%27Ruby%201.9.2%27%20and%20was%20realised%20in%20August%202011%2C%20it%20brings%20many%20new%20features%20and%20bug%20fixeses.%20The%20most%20signifiant%20changes%20are&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+Ruby+on+Rails+Ubuntu+12.04+using+RVM+and+Ruby+1.9.3&amp;link=http://www.the-tech-tutorial.com/?p=1868&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework%20that%20runs%20the%20Ruby%20programing%20language.%20The%20latest%20version%20of%20the%20Ruby%20is%20%27Ruby%201.9.2%27%20and%20was%20realised%20in%20August%202011%2C%20it%20brings%20many%20new%20features%20and%20bug%20fixeses.%20The%20most%20signifiant%20changes%20are&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+Ruby+on+Rails+Ubuntu+12.04+using+RVM+and+Ruby+1.9.3&amp;link=http://www.the-tech-tutorial.com/?p=1868&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework%20that%20runs%20the%20Ruby%20programing%20language.%20The%20latest%20version%20of%20the%20Ruby%20is%20%27Ruby%201.9.2%27%20and%20was%20realised%20in%20August%202011%2C%20it%20brings%20many%20new%20features%20and%20bug%20fixeses.%20The%20most%20signifiant%20changes%20are&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=88&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="https://shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.the-tech-tutorial.com/?feed=rss2&#038;p=1868</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How To Install Ruby on Rails Ubuntu Server 11.10</title>
		<link>http://www.the-tech-tutorial.com/?p=1801</link>
		<comments>http://www.the-tech-tutorial.com/?p=1801#comments</comments>
		<pubDate>Fri, 11 Nov 2011 09:56:48 +0000</pubDate>
		<dc:creator>Tyler Allen</dc:creator>
				<category><![CDATA[Fix It]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Basic]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Easy]]></category>
		<category><![CDATA[installing mysql2]]></category>
		<category><![CDATA[installing sqlite3]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Simple]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[ubuntu 11.04]]></category>
		<category><![CDATA[ubutnu 11.10]]></category>

		<guid isPermaLink="false">http://www.the-tech-tutorial.com/?p=1801</guid>
		<description><![CDATA[Ruby Rails is a Web application framework created in 2004 intended as a rapid development web framework. It was intended to emphasize Convention over Configuration (CoC) meaning the developer only needs to specify unconventional aspects of the application. For example, if there is a class Sale in the model, the corresponding table in the database [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/11/rails.png"><img src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/11/rails.png" alt="" title="rails" width="87" height="111" class="alignleft size-full wp-image-1851" /></a><span>Ruby Rails</span> is a <span><span><span>Web</span> application</span> framework</span> created in 2004 intended as a <span>rapid development</span> <span>web framework</span>. It was intended to emphasize <span>Convention over Configuration</span> (CoC) meaning the developer only needs to specify unconventional aspects of the application. For example, if there is a class Sale in the model, the corresponding table in the database is called sales by default. It is only if one deviates from this convention, such as calling the table &#8220;products sold&#8221;, that the developer needs to write code regarding these names. It has also been designed around the &#8220;Don&#8217;t repeat yourself&#8221; principle. Both of these ways of thinking allow you, with <span>Ruby Rails<span>, to create excellent, <span>dynamic websites</span> very quickly. So to get started we need to setup a <span><span><span>Ruby</span> Rails</span> <span>development server</span></span> on <span>Ubuntu</span> (<span>Ubuntu 11.04</span>, <span>Ubuntu 11.10</span>)<span id="more-1801"></span></p>
<div style="width:350px; height:330px;background-image: url(http://www.the-tech-tutorial.com/wp-content/uploads/2011/03/add_back1.png); display: block; float: right; padding: 20px 25px 0px 30px;">
<script type="text/javascript"><!--
google_ad_client = "pub-2094089617852812";
/* 2011 In Text Box */
google_ad_slot = "1777411765";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>In this <span>tutorial</span> we are going to go through an install of <span><span><span>Ruby Rails</span> on Ubuntu</span> 11.10</span> using <span>Ruby 1.8</span>. This will work on previous Ubuntu versions however Ubuntu 11.10 is the version I tested this walk-through. </p>
<p>Before we go anywhere we need to install and setup a <span>MySQL</span> server as <span>Ruby Rails</span> requires a database to function correctly, to do this open your terminal and type:</p>
<pre>sudo apt-get install mysql-server</pre>
<p>when prompted enter the root password for your database server, remember this as you&#8217;ll need it later.</p>
<p>Once your <span><span>MySQL</span> database</span> is installed we need to install the <span>Ruby</span> language. The <span>Ruby</span> language is the programing that <span>Ruby Rails</span> runs on. <span>Ruby</span> itself was designed before <span>Ruby Rails</span> as a dynamic, reflective, general-purpose object-oriented programming language. It was inspired by Perl with Smalltalk-like features. I strongly recommend you learn to make a few programs in ruby before moving onto working work ruby rails, a great free e-book to teach you <span>Ruby</span> can be <a href="http://ruby-doc.org/docs/ProgrammingRuby/">found here</a>. There are also a few other programs that are needed to run <span>Ruby Rails</span>, these will all be installed in this step so it may take a while:</p>
<pre>sudo apt-get install ruby ruby-full libzlib-ruby rvm rdoc irb make sqlite3 libmysql-ruby libmysqlclient-dev nodejs</pre>
<p>Now we need to install <span>Gem</span>, this is a little like &#8220;Apt-get&#8221; or &#8220;Aptitude&#8221; however it’s designed just to download modules for <span>Ruby</span> &#038; <span>Ruby Rails</span>. Personly I&#8217;ve had problems when <span>installing <span>Gem</span></span> on <span>Ubuntu</span> using <span>apt-get</span> so for this tutoiral we&#8217;ll install using the <span>Ruby</span> file downloaded frm the <span>rubyonrails</span>.org website. </p>
<pre>
cd ~
wget http://rubyforge.org/frs/download.php/75475/rubygems-1.8.11.tgz
tar -xf rubygems-1.8.11.tgz
cd rubygems-1.8.11
sudo ruby setup.rb
</pre>
<p>Once gem is installed we need to use it to download a few packages (or <span>Gems</span>),</p>
<pre>
sudo gem1.8 install mysql2 -v '0.3.10'
</pre>
<p>Once this is downloaded and installed by <span>Gem</span> its time to download and install <span>Rails</span> itself. Installing Rails from <span>Gem</span> can take a while and on my install it always appears to <span>hang</span> for a while. If this happens to you don’t worry it is doing its job, just wait a few more minutes.</p>
<pre>sudo gem1.8 install rails</pre>
<p>Now its time to <span>setup</span> a new site, the following step will create the site new_<span>rails</span>, feel free to change this to what you like for the remainder of this tutorial,</p>
<pre>rails new new_rails -d mysql </pre>
<p>Once this completed your ready to setup your database, todo this open your mysql client with</p>
<pre>mysql -u root -p</pre>
<p>and create the database for youe app (here we use [APPNAME]_development, you should subsituite your app name in the APPNAME section)</p>
<pre>CREATE DATABASE new_rails_development;</pre>
<p>Now you can exit your mysql client with the &#8220;Exit&#8221; command. Now you&#8217;ll need to enter your <span><span><span>MySQL</span> database</span> password</span> into the rails config. You do this by editing a config file saved in the config directory of your new site,</p>
<pre>nano ~/new_rails/config/database.yml</pre>
<p>Once you have this file open you&#8217;ll need to fill in the password fields with your database password, you only need to do this for the password field (i.e the development DB). </p>
<p>Now its time to start your Ruby Rails Server,</p>
<pre>cd new_rails
sudo rails server</pre>
<p>you should see something that looks like this:<br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/11/ServStarted.jpg"><img class="aligncenter size-full wp-image-1818" title="ServStarted" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/11/ServStarted.jpg" alt="" width="505" height="378" /></a></p>
<p>Now that your <span>server</span> is running go to your <span>web</span> browser and enter the address</p>
<pre>http://[YOUR IP]:3000/</pre>
<p><center><br />
<script type="text/javascript"><!--
google_ad_client = "ca-pub-2094089617852812";
/* 2011 Bottom */
google_ad_slot = "5825267234";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center><br />
If your development server is setup correclty then you should see the folowing window:<br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/11/Running.jpg"><img class="aligncenter size-full wp-image-1819" title="Running" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/11/Running.jpg" alt="" width="500" height="366" /></a><br />
If you see this screen then you’ve setup your Ruby Rails development server on Ubuntu 11.04. There are many more steps required in building a website using ruby rails, these are all out of the scope of this tutorial, however you can find a great starting <a href=" http://guides.rubyonrails.org/getting_started.html">guide here</a>, just scroll down to Step 4 to start where we have left off.</p>
<p>If you have any problems or comments please feel free to leave them in the comments section and I&#8217;ll try and get back to you asap. </p>
<p>When I was setting up this tutorial I ran into several problems with <span>Ubuntu</span> and <span>Ruby Rails</span>, these were the following error messages:</p>
<pre><span><span><span>An error</span> occured</span> while <span>installing mysql2</span> (0.3.10)</span>
<span>An<span> <span>error</span> occured</span></span> while <span>installing sqlite3</span> (1.3.4)</pre>
<p>If have tried installing <span>Ruby Rails on Ubuntu</span> then start again following the above steps in order and you won’t have these problems. However if cant be botherd to install <span><span>Ruby</span> On <span>Rails</span></span> again then running the following commands should fix the problem:</p>
<pre>
sudo apt-get install ruby ruby-full libzlib-ruby rdoc irb make sqlite3 libmysql-ruby libmysqlclient-dev nodejs
rails new new_rails -d mysql</pre>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="standard" count="" href="http://www.the-tech-tutorial.com/?p=1801"></g:plusone></div>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=How+To+Install+Ruby+on+Rails+Ubuntu+Server+11.10&amp;link=http://www.the-tech-tutorial.com/?p=1801&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework.%20It%20was%20intended%20to%20emphasize%20Convention%20over%20Configuration%20%28CoC%29%20meaning%20the%20developer%20only%20needs%20to%20specify%20unconventional%20aspects%20of%20the%20application.%20For%20example%2C%20if%20there%20is%20a%20class%20Sale%20in%20th&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=How+To+Install+Ruby+on+Rails+Ubuntu+Server+11.10&amp;link=http://www.the-tech-tutorial.com/?p=1801&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework.%20It%20was%20intended%20to%20emphasize%20Convention%20over%20Configuration%20%28CoC%29%20meaning%20the%20developer%20only%20needs%20to%20specify%20unconventional%20aspects%20of%20the%20application.%20For%20example%2C%20if%20there%20is%20a%20class%20Sale%20in%20th&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.shareaholic.com/api/share/?title=How+To+Install+Ruby+on+Rails+Ubuntu+Server+11.10&amp;link=http://www.the-tech-tutorial.com/?p=1801&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework.%20It%20was%20intended%20to%20emphasize%20Convention%20over%20Configuration%20%28CoC%29%20meaning%20the%20developer%20only%20needs%20to%20specify%20unconventional%20aspects%20of%20the%20application.%20For%20example%2C%20if%20there%20is%20a%20class%20Sale%20in%20th&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=&amp;tags=&amp;ctype=" rel="nofollow" class="external" title=""></a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=How+To+Install+Ruby+on+Rails+Ubuntu+Server+11.10&amp;link=http://www.the-tech-tutorial.com/?p=1801&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework.%20It%20was%20intended%20to%20emphasize%20Convention%20over%20Configuration%20%28CoC%29%20meaning%20the%20developer%20only%20needs%20to%20specify%20unconventional%20aspects%20of%20the%20application.%20For%20example%2C%20if%20there%20is%20a%20class%20Sale%20in%20th&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=How+To+Install+Ruby+on+Rails+Ubuntu+Server+11.10&amp;link=http://www.the-tech-tutorial.com/?p=1801&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework.%20It%20was%20intended%20to%20emphasize%20Convention%20over%20Configuration%20%28CoC%29%20meaning%20the%20developer%20only%20needs%20to%20specify%20unconventional%20aspects%20of%20the%20application.%20For%20example%2C%20if%20there%20is%20a%20class%20Sale%20in%20th&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=How+To+Install+Ruby+on+Rails+Ubuntu+Server+11.10&amp;link=http://www.the-tech-tutorial.com/?p=1801&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework.%20It%20was%20intended%20to%20emphasize%20Convention%20over%20Configuration%20%28CoC%29%20meaning%20the%20developer%20only%20needs%20to%20specify%20unconventional%20aspects%20of%20the%20application.%20For%20example%2C%20if%20there%20is%20a%20class%20Sale%20in%20th&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.shareaholic.com/api/share/?title=How+To+Install+Ruby+on+Rails+Ubuntu+Server+11.10&amp;link=http://www.the-tech-tutorial.com/?p=1801&amp;notes=Ruby%20Rails%20is%20a%20Web%20application%20framework%20created%20in%202004%20intended%20as%20a%20rapid%20development%20web%20framework.%20It%20was%20intended%20to%20emphasize%20Convention%20over%20Configuration%20%28CoC%29%20meaning%20the%20developer%20only%20needs%20to%20specify%20unconventional%20aspects%20of%20the%20application.%20For%20example%2C%20if%20there%20is%20a%20class%20Sale%20in%20th&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=88&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="https://shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.the-tech-tutorial.com/?feed=rss2&#038;p=1801</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Developing Wesbites For iPhones</title>
		<link>http://www.the-tech-tutorial.com/?p=1631</link>
		<comments>http://www.the-tech-tutorial.com/?p=1631#comments</comments>
		<pubDate>Wed, 10 Aug 2011 09:41:52 +0000</pubDate>
		<dc:creator>Tyler Allen</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[code example]]></category>
		<category><![CDATA[detect]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iPod]]></category>
		<category><![CDATA[res]]></category>
		<category><![CDATA[size]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.the-tech-tutorial.com/?p=1631</guid>
		<description><![CDATA[So I’ve been developing a few websites mainly to be viewed on iPhones and iPods and this has raised several issues. Obviously you have to develop for mobile browsers such as safari which runs on iPhones or iPods and develop accordingly for this browser and the unique screen resolutions used on mobile devices. In this [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/IPhone_4_in_hand.jpg"><img class="alignleft size-full wp-image-1714" title="The iPhone 4" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/IPhone_4_in_hand.jpg" alt="" width="86" height="70" /></a>So I’ve been developing a few websites mainly to be viewed on <span>iPhones</span> and <span>iPods</span> and this has raised several issues. Obviously you have to develop for mobile browsers such as safari which runs on <span><span>iPhone</span>s</span> or <span><span>iPod</span>s</span> and <span>develop</span> accordingly for this <span>browser</span> and the unique <span>screen resolutions</span> used on <span>mobile devices</span>. In this article I’m going to look at, what I feel, are the most <span>important <span><span>code</span> snippets</span></span> you&#8217;ll need to get started <span>developing for <span><span>iPhone</span>s</span> or <span><span>iPod</span>s</span></span>.<span id="more-1631"></span></p>
<h1></h1>
<h1>Detect <span>iPhone</span>s</h1>
<p>First off we need to be able to detect <span>iPhone</span>s in order to develop for them, after all we don’t want to develop solely for <span><span>iPhone</span>s</span> so we need know when an <span>iPhone</span> is viewing the page to make the relevant adjustments.</p>
<h4>PHP</h4>
<p><span>To <span><span>detect iPhone</span>s in PHP</span></span> use the folowing code:</p>
<pre class="brush:php">if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod')) {
    //TODO: Enter your iPhone/iPod code here
}</pre>
<h4>JavaScript</h4>
<p><span>To <span><span>detect iPhone</span>s in JavaScript</span></span> use the folowing code:</p>
<pre class="brush:js">if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
   //TODO: Enter your iPhone/iPod code here
}</pre>
<p><em><strong>Source:</strong> <a href="http://davidwalsh.name/detect-iphone" target="_blank">http://davidwalsh.name/detect-iphone</a></em></p>
<h1></h1>
<h1><span>Define Viewport for <span>iPhone</span></span></h1>
<p>This is an important feature to include in all your <span><span><span>iPhone</span> or <span>iPod</span> enabled page</span>s</span>, without this your page will open as if its <span>zoomed out</span>, trust me its annoying. To stop this from happening you need to include <em>width=device-width </em>to tell safari that the website is the same width as the <span><span>iPhone</span> Screen</span>, to do this simply include this meta tag in your pages header:</p>
<pre class="brush:xml">&lt;meta name="viewport" content="width=device-width;&gt;</pre>
<p>if you are developing and iPhone only page you can also restrict the user from scaling the page and messing up your nice layout, to do this set the initial-scale &amp; maximum-scale values to 1.0:</p>
<pre class="brush:xml">&lt;meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"&gt;</pre>
<p><em><strong>Source: </strong></em><a href="http://www.engageinteractive.co.uk/blog/2008/06/19/tutorial-building-a-website-for-the-iphone/" target="_blank">engageinteractive.co.uk/../tutorial-building-a-website-for-the-iphone/</a></p>
<p><center><br />
<script type="text/javascript">// <![CDATA[
 google_ad_client = "ca-pub-2094089617852812"; /* 2011 Bottom */ google_ad_slot = "5825267234"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">// <![CDATA[</p>
<p>// ]]&gt;</script></center></p>
<h1></h1>
<h1><span>Adding an <span><span>iPhone</span> home screen icon</span></span></h1>
<p>When someone adds a <span>webpage</span> to their <span>home screen on the <span>iPhone</span></span> then a new <span>icon</span> is generated so that the user can quickly access the page. We can choose what that <span>icon</span> is by setting <em>rel=&#8221;apple-touch-icon&#8221;</em> to the desired <span>icon</span>. First you need to design a relevant <span>icon</span>, it needs to be in .PNG format and <span>57px by 57px</span>. As for the code simply add this to your header replacing the link with the link to your icon file:</p>
<pre class="brush:xml">&lt;rel="apple-touch-icon" href="images/template/engage.png"/&gt;</pre>
<p><em><strong>Source: </strong></em><a href="http://www.engageinteractive.co.uk/blog/2008/06/19/tutorial-building-a-website-for-the-iphone/" target="_blank">engageinteractive.co.uk/../tutorial-building-a-website-for-the-iphone/</a></p>
<h1></h1>
<h1>Common iPhone page layout</h1>
<p>Most pages developed for <span>iPhones</span> have a single column structure with a floating width that contains three main sections, the header, content and footer. This layout is used by many websites including Flickr, here is a breakdown of the <span>iPhone</span> Flickr page:</p>
<p><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/ip2.gif"><img class="aligncenter size-full wp-image-1668" title="ip2" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/ip2.gif" alt="" width="417" height="339" /></a></p>
<p><strong></strong><em><strong>Source: </strong></em><a href="http://woorkup.com/2010/01/10/best-practices-to-develop-perfect-websites-for-iphone-and-mobile-devices/" target="_blank">woorkup.com/&#8230;/best-practices-to-develop-perfect-websites-for-iphone-and-mobile-devices/</a></p>
<p>A simple example of how to <span>code</span> this <span>simple <span>layout</span></span> can be seen below, note we never set a relative width in the CSS, this this may stop the page from filling the iPhones screen:</p>
<h6>CSS:</h6>
<pre class="brush:css">#header{
	background:#0CF;
}
#content{
	background:#CCC;
	height:200px;
}
#footer{
	background:#0CF;
}</pre>
<h6>HTML:</h6>
<pre class="brush:xml">&lt;body&gt;
&lt;div id="header"&gt;
	&lt;center&gt;Header&lt;/center&gt;
&lt;/div&gt;
&lt;div id="content"&gt;
	&lt;center&gt;Content&lt;/center&gt;
&lt;/div&gt;
&lt;div id="footer"&gt;
	&lt;center&gt;Footer&lt;/center&gt;
&lt;/div&gt;
&lt;/body&gt;</pre>
<h1></h1>
<h1>Common iPhone page NavBar</h1>
<p>Most <span><span>iPhone</span> <span>pages</span></span> have a header that often contains a logo and a navigation bar. A navigation bar is an important part of any page, without it the users will be stuck on one page, and we don’t want that. Here is a good example of a navigation bar to use in your iPhone page headers:</p>
<h6>EXAMPLE :</h6>
<p><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Nav_Head_iphone.jpg"><img class="aligncenter size-full wp-image-1677" title="Nav_Head_iphone" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Nav_Head_iphone.jpg" alt="" width="404" height="62" /></a></p>
<h6>CSS:</h6>
<pre class="brush:css">#header{
	height:25px;
}
div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0;padding:0}
ol,ul{list-style:none}
#nav{position:relative;line-height:14px}
#nav_main{height:30px;color:#111}
#nav_main li{float:left;width:25%;margin:2px 0 0 -1px;background:#f3f3f3;border:1px solid #e3e3e3;border-width:0 0 1px 1px;text-align:center}
#nav_main li.first{border-left:none}
#nav_main li.selected{z-index:10;margin-top:0;margin-left:-2px;background:#fff;border-width:1px;border-bottom:1px solid #fff;font-weight:bold}
#nav_main li.last.selected{border-right:none}
#nav_main li a{display:block;padding:6px 0 7px}
#nav_main li.selected a{padding-top:7px;color:#000}</pre>
<h6>HTML:</h6>
<pre class="brush:xml">&lt;div id="header"&gt;
     &lt;div id="logo"&gt;
         &lt;img src="" width="100" height="30" alt="LOGO"&gt;
     &lt;/div&gt;
     &lt;div id="nav"&gt;
        &lt;ul id="nav_main"&gt;
            &lt;li id="activity-tab"&gt;&lt;a href="/activity/" &gt;Activity&lt;/a&gt;&lt;/li&gt;
            &lt;li id="you-tab"&gt;&lt;a href="/photos/tyleruk2000/" &gt;You&lt;/a&gt;&lt;/li&gt;
            &lt;li id="contacts-tab"&gt;&lt;a href="/people/" &gt;Contacts&lt;/a&gt;&lt;/li&gt;
            &lt;li id="more-tab"&gt;&lt;a href="/more"&gt;More&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;    
&lt;/div&gt;</pre>
<h1></h1>
<h1><span>Starter <span><span>iPhone Page</span></span> Template</span></h1>
<p>This is a very <span>simple <span>template</span></span> I put together to <span>get you <span>started creating iPhone websites</span></span>, it has a logo in the header, a <span>simple Navigation bar</span> and a simple footer:</p>
<h6>EXAMPLE :</h6>
<p style="text-align: center;"><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo_temp.png"><img class="aligncenter size-full wp-image-1702" title="photo_temp" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo_temp.png" alt="" width="230" height="346" /></a></p>
<h6>CODE:</h6>
<p><center><br />
<script type="text/javascript">// <![CDATA[
 google_ad_client = "ca-pub-2094089617852812"; /* 2011 Bottom */ google_ad_slot = "5825267234"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">// <![CDATA[</p>
<p>// ]]&gt;</script></center></p>
<pre class="brush:xml">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;iPhoneStartTemplate&lt;/title&gt;

&lt;style&gt;
div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0;padding:0}
ol,ul{list-style:none}
#nav{position:relative;line-height:14px;}
#nav_main{height:30px;color:#111}
#nav_main li{float:left;width:25%;margin:2px 0 0 -1px;background:#f3f3f3;border:1px solid #e3e3e3;border-width:0 0 1px 1px;text-align:center}
#nav_main li.first{border-left:none}
#nav_main li.selected{z-index:10;margin-top:0;margin-left:-2px;background:#fff;border-width:1px;border-bottom:1px solid #fff;font-weight:bold}
#nav_main li.last.selected{border-right:none}
#nav_main li a{display:block;padding:6px 0 7px}
#nav_main li.selected a{padding-top:7px;color:#000}
#header{background:#f3f3f3;}
#content{background:#f7f7f7;border-width:1px;border-bottom:1px solid #fff;}
#footer{background:#f3f3f3;border-width:1px;border-top:1px solid #DDD;font-size:x-small;height:31px;}
#logo.footer{float:left;}
#footer_nav{float:right;font-size:x-small; margin-top:8px; margin-right:5px;}
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;!----------------------START OF HEADER----------------------&gt;
&lt;div id="header" class="toolbar"&gt;
	&lt;div id="logo"&gt;
        &lt;img src="" width="100" height="30" alt="LOGO"&gt;
    &lt;/div&gt;
	&lt;div id="nav"&gt;
		&lt;ul id="nav_main"&gt;
			&lt;li class="first"&gt;&lt;a href="/activity/" &gt;Activity&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href="/photos/" &gt;You&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href="/people/" &gt;Contacts&lt;/a&gt;&lt;/li&gt;
			&lt;li class="last"&gt;&lt;a href="/more"&gt;More&lt;/a&gt;&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/div&gt;
&lt;/div&gt;
&lt;!----------------------START OF MAIN CONTENT----------------------&gt;
&lt;div id="content"&gt;
  &lt;p&gt;Ve da aspetta deserta purezza porpora. Ci ricomincia emergevano mi inebriarti persuadere riprodurre trascinato. Cosi nevi far sul qui dita ella. Rote vero mani un pare me teco. Ferro ma ci su volto da umile. Sapro prima prime tue getti manca mia. Ardi sara dara sul tele tra meco. &lt;/p&gt;
&lt;/div&gt;
&lt;!----------------------START OF FOOTER----------------------&gt;
&lt;div id="footer"&gt;
    &lt;div id="logo" class="footer"&gt;&lt;img src="" width="100" height="30" alt="LOGO"&gt;&lt;/div&gt;
    &lt;div id="footer_nav"&gt;&lt;span style="text-align:right"&gt;&lt;a href="/activity/"&gt;HOME&lt;/a&gt; | &lt;a href="/photos/"&gt;TOP&lt;/a&gt; | &lt;a href="/people/"&gt;PRINT&lt;/a&gt; | &lt;a href="/forum/"&gt;FORUM&lt;/a&gt; | &lt;a href="/about/"&gt;ABOUT&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<h1><span>Screen Resolution</span></h1>
<p>This is important to know as if you’re using pictures or static dimensions you don’t want your content to spill over the edge of the screen. This isn’t so much of a problem if your content is rather high as users are used to scrolling up and down however if you include wide content you start messing with the zoom level and the page may not display as you originally as you thought. Another difficulty is that there are two types of iPhone resolution, that of the iPhone and the iPhone 4 so make sure you test your sites on both resolutions, they are:</p>
<p><strong>iPhone:</strong> 320&#215;480</p>
<p><strong>iPhone 4:</strong> 640&#215;960</p>
<h1><span>Inspiration</span></h1>
<p>Here I have included my favourite <span><span><span>websites</span> optimized</span> for the iPhone</span>, though this isn’t realy a tip for <span><span><span>developing websites</span> for iPhone<span>s</span> its always <span>helpful</span> to look at other sites to see if you can learn something from how they do it. Notice none of these sites (apart from flicker) don&#8217;t use a lot of images, this is to make much cleaner and user friendly on the small screens and a lot quicker to load over the relatively slow internet connection that <span>iphones</span> have:</span></span></p>
<p style="text-align: center;"><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo1.png"><img class="aligncenter size-full wp-image-1685" title="photo1" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo1.png" alt="" width="384" height="576" /></a></p>
<p style="text-align: center;"><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo2.png"><img class="aligncenter size-full wp-image-1686" title="photo2" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo2.png" alt="" width="384" height="576" /></a></p>
<p style="text-align: center;"><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo3.png"><img class="aligncenter size-full wp-image-1687" title="photo3" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo3.png" alt="" width="384" height="576" /></a></p>
<p style="text-align: center;"><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo4.png"><img class="aligncenter size-full wp-image-1691" title="photo4" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo4.png" alt="" width="384" height="576" /></a><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo4.png"><br />
</a></p>
<p style="text-align: center;"><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo5.png"><img class="aligncenter size-full wp-image-1684" title="photo5" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/photo5.png" alt="" width="384" height="576" /></a></p>
<p>I hope you find this information helpful, if you have any comments or questions please leave a comment.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="standard" count="" href="http://www.the-tech-tutorial.com/?p=1631"></g:plusone></div>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=Developing+Wesbites+For+iPhones&amp;link=http://www.the-tech-tutorial.com/?p=1631&amp;notes=So%20I%E2%80%99ve%20been%20developing%20a%20few%20websites%20mainly%20to%20be%20viewed%20on%20iPhones%20and%20iPods%20and%20this%20has%20raised%20several%20issues.%20Obviously%20you%20have%20to%20develop%20for%20mobile%20browsers%20such%20as%20safari%20which%20runs%20on%20iPhones%20or%20iPods%20and%20develop%20accordingly%20for%20this%20browser%20and%20the%20unique%20screen%20resolutions%20used%20on%20mob&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=Developing+Wesbites+For+iPhones&amp;link=http://www.the-tech-tutorial.com/?p=1631&amp;notes=So%20I%E2%80%99ve%20been%20developing%20a%20few%20websites%20mainly%20to%20be%20viewed%20on%20iPhones%20and%20iPods%20and%20this%20has%20raised%20several%20issues.%20Obviously%20you%20have%20to%20develop%20for%20mobile%20browsers%20such%20as%20safari%20which%20runs%20on%20iPhones%20or%20iPods%20and%20develop%20accordingly%20for%20this%20browser%20and%20the%20unique%20screen%20resolutions%20used%20on%20mob&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.shareaholic.com/api/share/?title=Developing+Wesbites+For+iPhones&amp;link=http://www.the-tech-tutorial.com/?p=1631&amp;notes=So%20I%E2%80%99ve%20been%20developing%20a%20few%20websites%20mainly%20to%20be%20viewed%20on%20iPhones%20and%20iPods%20and%20this%20has%20raised%20several%20issues.%20Obviously%20you%20have%20to%20develop%20for%20mobile%20browsers%20such%20as%20safari%20which%20runs%20on%20iPhones%20or%20iPods%20and%20develop%20accordingly%20for%20this%20browser%20and%20the%20unique%20screen%20resolutions%20used%20on%20mob&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=&amp;tags=&amp;ctype=" rel="nofollow" class="external" title=""></a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=Developing+Wesbites+For+iPhones&amp;link=http://www.the-tech-tutorial.com/?p=1631&amp;notes=So%20I%E2%80%99ve%20been%20developing%20a%20few%20websites%20mainly%20to%20be%20viewed%20on%20iPhones%20and%20iPods%20and%20this%20has%20raised%20several%20issues.%20Obviously%20you%20have%20to%20develop%20for%20mobile%20browsers%20such%20as%20safari%20which%20runs%20on%20iPhones%20or%20iPods%20and%20develop%20accordingly%20for%20this%20browser%20and%20the%20unique%20screen%20resolutions%20used%20on%20mob&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=Developing+Wesbites+For+iPhones&amp;link=http://www.the-tech-tutorial.com/?p=1631&amp;notes=So%20I%E2%80%99ve%20been%20developing%20a%20few%20websites%20mainly%20to%20be%20viewed%20on%20iPhones%20and%20iPods%20and%20this%20has%20raised%20several%20issues.%20Obviously%20you%20have%20to%20develop%20for%20mobile%20browsers%20such%20as%20safari%20which%20runs%20on%20iPhones%20or%20iPods%20and%20develop%20accordingly%20for%20this%20browser%20and%20the%20unique%20screen%20resolutions%20used%20on%20mob&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=Developing+Wesbites+For+iPhones&amp;link=http://www.the-tech-tutorial.com/?p=1631&amp;notes=So%20I%E2%80%99ve%20been%20developing%20a%20few%20websites%20mainly%20to%20be%20viewed%20on%20iPhones%20and%20iPods%20and%20this%20has%20raised%20several%20issues.%20Obviously%20you%20have%20to%20develop%20for%20mobile%20browsers%20such%20as%20safari%20which%20runs%20on%20iPhones%20or%20iPods%20and%20develop%20accordingly%20for%20this%20browser%20and%20the%20unique%20screen%20resolutions%20used%20on%20mob&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.shareaholic.com/api/share/?title=Developing+Wesbites+For+iPhones&amp;link=http://www.the-tech-tutorial.com/?p=1631&amp;notes=So%20I%E2%80%99ve%20been%20developing%20a%20few%20websites%20mainly%20to%20be%20viewed%20on%20iPhones%20and%20iPods%20and%20this%20has%20raised%20several%20issues.%20Obviously%20you%20have%20to%20develop%20for%20mobile%20browsers%20such%20as%20safari%20which%20runs%20on%20iPhones%20or%20iPods%20and%20develop%20accordingly%20for%20this%20browser%20and%20the%20unique%20screen%20resolutions%20used%20on%20mob&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=88&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="https://shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.the-tech-tutorial.com/?feed=rss2&#038;p=1631</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install and Configure a Ubuntu 11.04 Snort-MySQL Honeypot</title>
		<link>http://www.the-tech-tutorial.com/?p=1578</link>
		<comments>http://www.the-tech-tutorial.com/?p=1578#comments</comments>
		<pubDate>Tue, 09 Aug 2011 13:05:39 +0000</pubDate>
		<dc:creator>Tyler Allen</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Basic]]></category>
		<category><![CDATA[configure]]></category>
		<category><![CDATA[honeypot]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[network intrusion prevention]]></category>
		<category><![CDATA[picture]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[screen shorts]]></category>
		<category><![CDATA[Setup]]></category>
		<category><![CDATA[Simple]]></category>
		<category><![CDATA[snort]]></category>
		<category><![CDATA[Tutoiral]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[ubuntu 11.04]]></category>

		<guid isPermaLink="false">http://www.the-tech-tutorial.com/?p=1578</guid>
		<description><![CDATA[An Intrusion Detection system is like a burglar alarm for your computer. It monitors you network and system activities for malicious activities or policy violations and reports to some kind of management station. This is great as it lets you know who were when &#38; how people are trying to break into your network and [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2010/09/snort.jpg"><img class="alignleft size-full wp-image-864" title="snort" src="http://www.the-tech-tutorial.com/wp-content/uploads/2010/09/snort.jpg" alt="" width="174" height="95" /></a>An <span><span>Intrusion Detection</span> system</span> is like a burglar alarm for your computer. It monitors you network and system activities for malicious activities or policy violations and reports to some kind of <span>management station</span>. This is great as it lets you know who were when &amp; how people are trying to break into your network and knowing this is half the battle. You may be thinking that this isn’t enough and you want to block all hacks from happening, well most <span>IDS</span> systems include some “<span><span>Network Intrusion</span> Prevention</span>” features. However the main concern should be closing up vulnerabilities rather than blocking someone already trying to hack your systems, after all it’s a bit late if they are already in your system, and this way you may accedently block innocent users.<br />
<span id="more-1578"></span><br />
Another common use of an <span><span>Intrusion Detection</span> system</span> is to use it as a <span>honeypot</span>. In Wikipedia’s words a <span>honeypot</span> is &#8220;In computer terminology, a <strong><span>honeypot</span></strong> is a <a title="Trap (tactic)" href="http://en.wikipedia.org/wiki/Trap_%28tactic%29">trap</a> set to detect, deflect, or in some manner counteract attempts at unauthorized use of <a title="Information systems" href="http://en.wikipedia.org/wiki/Information_systems">information systems</a>.&#8221;. Basically if you trying to find some <span>hackers</span> address or an active <span>botnet</span> then installing a <span>honeypot</span> on a popular webserver is a good way to go about this.</p>
<div style="width:350px; height:330px;background-image: url(http://www.the-tech-tutorial.com/wp-content/uploads/2011/03/add_back1.png); display: block; float: left; padding: 20px 25px 0px 30px;">
<script type="text/javascript"><!--
google_ad_client = "pub-2094089617852812";
/* 2011 In Text Box */
google_ad_slot = "1777411765";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>So what the best <span>IDS</span>, well <a href="http://infoworld.com/" target="_blank">infoworld.com</a> said that the <a href="http://www.infoworld.com/d/open-source/greatest-open-source-software-all-time-776?source=fssr" target="_blank">The <span>greatest open source software of all time</span></a> was <a title="Snort Homepage" href="http://www.snort.org/" target="_blank">Snort</a>, and if it’s the <span><span>best</span> open source software of all time</span>, you can sure as hell bet it’s the <span>best</span> <span>open source <span>IDS</span></span>. <span>Snort</span> contains a full featured <span>IDS</span> as well as receiving regular updates to its rules library as well as great <span><span>Network <span>Intrusion</span> Prevention</span></span> features. So let’s discuss how to install this and get it reporting to a <span><span>MySQL</span> <span>database</span></span>.</p>
<p>In this tutorial we are going to be setting up a <span><span>snort</span> server</span> to run and <span>monitor a single machine</span>, this is great for <span>protecting your webserver</span> or creating a <span>honeypot</span>. However if you want an <span>IDS</span> to monitor your entire network this solution won&#8217;t work, you&#8217;ll need to buy a switch with a monitoring port (most manages switches) so that a copy of all the data sent across the network is mirrored to your snort server, if you do have this function turn it on and follow this tutorial as normal.</p>
<p>So let’s get started, first we need to install some base packages, mainly <span>LAMP</span> <em>(<span>Linux</span>, <span>Apache</span>, <span>MySQL</span> &#038; PHP)</em> so type into your terminal:</p>
<pre>sudo tasksel install lamp-server</pre>
<p>During this install you&#8217;ll be asked for a password to set for the root account on your new <span>MySQL server</span>, be sure to remember this as you&#8217;ll need it later.</p>
<p>Now we just need some tools to test the server later:</p>
<pre>sudo apt-get install nmap
sudo apt-get install nbtscan</pre>
<p>Just becuase its good practice remember to update your package lists:</p>
<pre>sudo apt-get update</pre>
<p>Now we&#8217;ve got that out of the way we can install <span>snort</span>:</p>
<pre>sudo apt-get install snort-mysql</pre>
<p>now you should see this widow, this is where you choose what range the snort server will <span>monitor</span>, if your just installing this on one machine enter the machines IP address followed by /32, if it’s a whole network use /24 at the end, for example:</p>
<p><strong><span>Single Machine</span>:</strong> 192.168.0.1/32<br />
<strong><span>Whole <span>Network</span></span>:</strong> 192.168.0.0/24 <em><small>(remember this will need a monitoring port)</small></em></p>
<p><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_1-090811.jpg"><img class="aligncenter size-full wp-image-1582" title="Snort_ubuntu_tut_1-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_1-090811.jpg" alt="" width="512" height="308" /></a></p>
<p>Next we are told we need a <span>database</span> to continue, don’t worry we installed this earlier, just press ok <em><small>(Tab to select)</small></em><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_2-090811.jpg"><img class="aligncenter size-full wp-image-1588" title="Snort_ubuntu_tut_2-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_2-090811.jpg" alt="" width="511" height="307" /></a></p>
<p>Now we are asked if we want a <span><span>database</span> setup</span>, click yes.<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_3-090811.jpg"><img class="aligncenter size-full wp-image-1589" title="Snort_ubuntu_tut_3-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_3-090811.jpg" alt="" width="506" height="140" /></a></p>
<p>Now we see the final config window, just click ok.<br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_4-090811.jpg"><img class="aligncenter size-full wp-image-1592" title="Snort_ubuntu_tut_4-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_4-090811.jpg" alt="" width="512" height="305" /></a></p>
<p>If you read the last window you see that we need to configure the <span>database</span>, this isn’t to hard just type:</p>
<pre>mysql -u root -p</pre>
<p>whitch will open the MySQL console window, in this type:</p>
<pre>create <span>database</span> <span>snort</span>;</pre>
<p>followed by</p>
<pre>quit</pre>
<p>Now we need to add some tables to the <span>database</span> we just created:</p>
<pre>cd /usr/share/doc/snort-mysql
zcat create_mysql.gz | mysql -u root -p snort</pre>
<p>Once that’s done we need to re-configure snort with the updated database, so type:</p>
<pre>sudo dpkg-reconfigure -plow snort-mysql</pre>
<p>This is the first screen you&#8217;ll see, unless you know otherwise select boot<br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_5-090811.jpg"><img class="aligncenter size-full wp-image-1593" title="Snort_ubuntu_tut_5-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_5-090811.jpg" alt="" width="512" height="207" /></a></p>
<p>Now we choose the <span>network</span> interface to <span>listen</span> on, unless you know otherwise leave this to its default value<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_6-090811.jpg"><img class="aligncenter size-full wp-image-1594" title="Snort_ubuntu_tut_6-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_6-090811.jpg" alt="" width="512" height="128" /></a></p>
<p>Here we renter our <span>network</span> selection, just leave as is and click ok<br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_1-090811.jpg"><img class="aligncenter size-full wp-image-1582" title="Snort_ubuntu_tut_1-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_1-090811.jpg" alt="" width="512" height="308" /></a></p>
<p>Here you choose whether you want to run snort in <span>promiscuous mode</span> or not. Even through i said that you can’t monitor over hosts (without a monitoring port) this is where you can, sort of, in promiscuous mode snort will monitor broadcasted events, personally I set this to no to reduce overhead but it’s up to you.<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_8-090811.jpg"><img class="aligncenter size-full wp-image-1596" title="Snort_ubuntu_tut_8-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_8-090811.jpg" alt="" width="508" height="180" /></a></p>
<p>Just leave this blank<br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_9-090811.jpg"><img class="aligncenter size-full wp-image-1581" title="Snort_ubuntu_tut_9-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_9-090811.jpg" alt="" width="512" height="156" /></a></p>
<p>Again this one is up to you, personally I like the <span>daily <span>email reports</span></span> but if you don’t want the hassle select no.<br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_10-090811.jpg"><img class="aligncenter size-full wp-image-1583" title="Snort_ubuntu_tut_10-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_10-090811.jpg" alt="" width="511" height="179" /></a></p>
<p>Since we have gone to the effort of setting up our <span>database</span> we might as well use it, select yes.<br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_11-090811.jpg"><img class="aligncenter size-full wp-image-1584" title="Snort_ubuntu_tut_11-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_11-090811.jpg" alt="" width="510" height="136" /></a></p>
<p>Enter 127.0.0.1 <em><small>If you want to use another <span>database</span> server here is where you would enter its address, however setting this up is out of the scope of this email.</small></em><br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_12-090811.jpg"><img class="aligncenter size-full wp-image-1585" title="Snort_ubuntu_tut_12-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_12-090811.jpg" alt="" width="509" height="169" /></a></p>
<p>Here enter the database name, which should be sort<br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_13-090811.jpg"><img class="aligncenter size-full wp-image-1586" title="Snort_ubuntu_tut_13-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_13-090811.jpg" alt="" width="510" height="167" /></a></p>
<p>For this tutorial we haven’t added any additional users so I’ve just used root, however this is bad practice, I recommend you add a dedicated snort user to you MySQL database, a good tutorial of that can be found <a href="http://dev.mysql.com/doc/refman/5.1/en/adding-users.html">here</a><br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_14-090811.jpg"><img class="aligncenter size-full wp-image-1587" title="Snort_ubuntu_tut_14-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_14-090811.jpg" alt="" width="511" height="168" /></a></p>
<p>Now enter the password for the user you selected in the previous step.<br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_15-090811.jpg"><img class="aligncenter size-full wp-image-1590" title="Snort_ubuntu_tut_15-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_15-090811.jpg" alt="" width="509" height="158" /></a></p>
<p>Now you have finished configuring snort, just click ok.<br />
<a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_16-090811.jpg"><img class="aligncenter size-full wp-image-1591" title="Snort_ubuntu_tut_16-090811" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/08/Snort_ubuntu_tut_16-090811.jpg" alt="" width="508" height="275" /></a></p>
<p>To start snort you need to confirm you have setup your database by typing:</p>
<pre>sudo rm /etc/snort/db-pending-config</pre>
<p>and start the Snort server<br />
<center><br />
<script type="text/javascript"><!--
google_ad_client = "ca-pub-2094089617852812";
/* 2011 Bottom */
google_ad_slot = "5825267234";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center></p>
<pre>sudo /etc/init.d/snort status</pre>
<p>Now if you want to see what attempted hacks have taken place simply type</p>
<pre>echo "select * from signature;" | mysql -u root -p snort</pre>
<p>this will show what attack signatures have been called.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="standard" count="" href="http://www.the-tech-tutorial.com/?p=1578"></g:plusone></div>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=Install+and+Configure+a+Ubuntu+11.04+Snort-MySQL+Honeypot&amp;link=http://www.the-tech-tutorial.com/?p=1578&amp;notes=An%20Intrusion%20Detection%20system%20is%20like%20a%20burglar%20alarm%20for%20your%20computer.%20It%20monitors%20you%20network%20and%20system%20activities%20for%20malicious%20activities%20or%20policy%20violations%20and%20reports%20to%20some%20kind%20of%20management%20station.%20This%20is%20great%20as%20it%20lets%20you%20know%20who%20were%20when%20%26amp%3B%20how%20people%20are%20trying%20to%20break%20in&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=Install+and+Configure+a+Ubuntu+11.04+Snort-MySQL+Honeypot&amp;link=http://www.the-tech-tutorial.com/?p=1578&amp;notes=An%20Intrusion%20Detection%20system%20is%20like%20a%20burglar%20alarm%20for%20your%20computer.%20It%20monitors%20you%20network%20and%20system%20activities%20for%20malicious%20activities%20or%20policy%20violations%20and%20reports%20to%20some%20kind%20of%20management%20station.%20This%20is%20great%20as%20it%20lets%20you%20know%20who%20were%20when%20%26amp%3B%20how%20people%20are%20trying%20to%20break%20in&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.shareaholic.com/api/share/?title=Install+and+Configure+a+Ubuntu+11.04+Snort-MySQL+Honeypot&amp;link=http://www.the-tech-tutorial.com/?p=1578&amp;notes=An%20Intrusion%20Detection%20system%20is%20like%20a%20burglar%20alarm%20for%20your%20computer.%20It%20monitors%20you%20network%20and%20system%20activities%20for%20malicious%20activities%20or%20policy%20violations%20and%20reports%20to%20some%20kind%20of%20management%20station.%20This%20is%20great%20as%20it%20lets%20you%20know%20who%20were%20when%20%26amp%3B%20how%20people%20are%20trying%20to%20break%20in&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=&amp;tags=&amp;ctype=" rel="nofollow" class="external" title=""></a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=Install+and+Configure+a+Ubuntu+11.04+Snort-MySQL+Honeypot&amp;link=http://www.the-tech-tutorial.com/?p=1578&amp;notes=An%20Intrusion%20Detection%20system%20is%20like%20a%20burglar%20alarm%20for%20your%20computer.%20It%20monitors%20you%20network%20and%20system%20activities%20for%20malicious%20activities%20or%20policy%20violations%20and%20reports%20to%20some%20kind%20of%20management%20station.%20This%20is%20great%20as%20it%20lets%20you%20know%20who%20were%20when%20%26amp%3B%20how%20people%20are%20trying%20to%20break%20in&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=Install+and+Configure+a+Ubuntu+11.04+Snort-MySQL+Honeypot&amp;link=http://www.the-tech-tutorial.com/?p=1578&amp;notes=An%20Intrusion%20Detection%20system%20is%20like%20a%20burglar%20alarm%20for%20your%20computer.%20It%20monitors%20you%20network%20and%20system%20activities%20for%20malicious%20activities%20or%20policy%20violations%20and%20reports%20to%20some%20kind%20of%20management%20station.%20This%20is%20great%20as%20it%20lets%20you%20know%20who%20were%20when%20%26amp%3B%20how%20people%20are%20trying%20to%20break%20in&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=Install+and+Configure+a+Ubuntu+11.04+Snort-MySQL+Honeypot&amp;link=http://www.the-tech-tutorial.com/?p=1578&amp;notes=An%20Intrusion%20Detection%20system%20is%20like%20a%20burglar%20alarm%20for%20your%20computer.%20It%20monitors%20you%20network%20and%20system%20activities%20for%20malicious%20activities%20or%20policy%20violations%20and%20reports%20to%20some%20kind%20of%20management%20station.%20This%20is%20great%20as%20it%20lets%20you%20know%20who%20were%20when%20%26amp%3B%20how%20people%20are%20trying%20to%20break%20in&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.shareaholic.com/api/share/?title=Install+and+Configure+a+Ubuntu+11.04+Snort-MySQL+Honeypot&amp;link=http://www.the-tech-tutorial.com/?p=1578&amp;notes=An%20Intrusion%20Detection%20system%20is%20like%20a%20burglar%20alarm%20for%20your%20computer.%20It%20monitors%20you%20network%20and%20system%20activities%20for%20malicious%20activities%20or%20policy%20violations%20and%20reports%20to%20some%20kind%20of%20management%20station.%20This%20is%20great%20as%20it%20lets%20you%20know%20who%20were%20when%20%26amp%3B%20how%20people%20are%20trying%20to%20break%20in&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=88&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="https://shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.the-tech-tutorial.com/?feed=rss2&#038;p=1578</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple C++ IRC Bot Template</title>
		<link>http://www.the-tech-tutorial.com/?p=1716</link>
		<comments>http://www.the-tech-tutorial.com/?p=1716#comments</comments>
		<pubDate>Sun, 07 Aug 2011 21:39:05 +0000</pubDate>
		<dc:creator>Tyler Allen</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[c plus plus]]></category>
		<category><![CDATA[C Plus Plus IRC Bot Source]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[IRC]]></category>
		<category><![CDATA[IRC Bot]]></category>
		<category><![CDATA[Simple]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Starter]]></category>
		<category><![CDATA[Template]]></category>

		<guid isPermaLink="false">http://www.the-tech-tutorial.com/?p=1716</guid>
		<description><![CDATA[I searched the Internet, for quit a while, and I couldn’t find the source for a simple IRC bot in C plus plus, so I decided to write one using a TCP Stream Socket in C++. It works by setting up a simple TCP Socket to a IRC server on port 6667. The IRC Bot [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2010/08/IRC-Vect_fin.jpg"><img class="alignleft size-full wp-image-725" title="IRC Vect_fin" src="http://www.the-tech-tutorial.com/wp-content/uploads/2010/08/IRC-Vect_fin.jpg" alt="IRC Funny Cartoon" width="89" height="90" /></a>I searched the Internet, for quit a while, and I couldn’t find the <span>source</span> for a <span>simple <span>IRC bot</span></span> in <span><span>C</span> plus plus</span>, so I decided to write one using a <span>TCP Stream Socket</span> in <span>C++</span>. It works by setting up a simple <span>TCP Socket</span> to a <span>IRC server</span> on port 6667. The <span>IRC Bot</span> then assigns a NICK to the connection and connects to a <span>IRC Channel</span>. From here you can code you own <span>commands</span> and replies. I originally developed this to <span>monitor <span><span>IRC</span> channel</span>s</span>, however I came across a problem, PING. IRC servers periodically <span>ping</span> all clients to see if they are connected, so I added some more <span>code to reply to these ping</span>’s so that the <span>bot</span> stays connected. <span id="more-1716"></span></p>
<p>Like I said this is only a base for a <span><span>IRC Bot</span> written in <span>C Plus Plus</span></span>, at the moment all it can do is reply to ping’s and reply to commands, however with a little bit of time you could create a full featured <span><span>IRC bot</span> in C++</span> from this <span>code</span>, so here it is:</p>
<p><center><br />
<script type="text/javascript">// <![CDATA[
 google_ad_client = "ca-pub-2094089617852812"; /* 2011 Bottom */ google_ad_slot = "5825267234"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">// <![CDATA[</p>
<p>// ]]&gt;</script></center><br />
<a href="http://www.the-tech-tutorial.com/wp-content/files/irc-bot.tar">DOWNLOAD SOURCE</a></p>
<h6>USAGE:</h6>
<pre class="brush:cpp">int main()
{
	IrcBot bot = IrcBot("NICK testBOT\r\n","USER guest tolmoon tolsun :Ronnie Reagan\r\n");
	bot.start();

  return 0;

}</pre>
<h6>HEADER:</h6>
<pre class="brush:cpp">/*
 * IrcBot.h
 *
 *  Created on: 15 Jul 2011
 *      Author: Tyler Allen
 */

#ifndef IRCBOT_H_
#define IRCBOT_H_

class IrcBot
{
public:
	IrcBot(char * _nick, char * _usr);
	virtual ~IrcBot();

	bool setup;

	void start();
	bool charSearch(char *toSearch, char *searchFor);

private:
	char *port;
	int s; //the socket descriptor

	char *nick;
	char *usr;

	bool isConnected(char *buf);
	char * timeNow();
	bool sendData(char *msg);
	void sendPong(char *buf);
	void msgHandel(char *buf);
};

#endif /* IRCBOT_H_ */</pre>
<h6>CPP File</h6>
<pre class="brush:cpp">/*
 * IrcBot.cpp
 *
 *  Created on: 15 Jul 2011
 *      Author: Tyler Allen
 */

#include "IrcBot.h"
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;
#include &lt;errno.h&gt;
#include &lt;string.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;netdb.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;sys/wait.h&gt;
#include &lt;signal.h&gt;
#include &lt;time.h&gt;

using namespace std;

#define MAXDATASIZE 100

IrcBot::IrcBot(char * _nick, char * _usr)
{
	nick = _nick;
	usr = _usr;
}

IrcBot::~IrcBot()
{
	close (s);
}

void IrcBot::start()
{
	struct addrinfo hints, *servinfo;

	//Setup run with no errors
	setup = true;

	port = "6667";

	//Ensure that servinfo is clear
	memset(&amp;hints, 0, sizeof hints); // make sure the struct is empty

	//setup hints
	hints.ai_family = AF_UNSPEC; // don't care IPv4 or IPv6
	hints.ai_socktype = SOCK_STREAM; // TCP stream sockets

	//Setup the structs if error print why
	int res;
	if ((res = getaddrinfo("irc.ubuntu.com",port,&amp;hints,&amp;servinfo)) != 0)
	{
		setup = false;
		fprintf(stderr,"getaddrinfo: %s\n", gai_strerror(res));
	}

	//setup the socket
	if ((s = socket(servinfo-&gt;ai_family,servinfo-&gt;ai_socktype,servinfo-&gt;ai_protocol)) == -1)
	{
		perror("client: socket");
	}

	//Connect
	if (connect(s,servinfo-&gt;ai_addr, servinfo-&gt;ai_addrlen) == -1)
	{
		close (s);
		perror("Client Connect");
	}

	//We dont need this anymore
	freeaddrinfo(servinfo);

	//Recv some data
	int numbytes;
	char buf[MAXDATASIZE];

	int count = 0;
	while (1)
	{
		//declars
		count++;

		switch (count) {
			case 3:
					//after 3 recives send data to server (as per IRC protacol)
					sendData(nick);
					sendData(usr);
				break;
			case 4:
					//Join a channel after we connect, this time we choose beaker
				sendData("JOIN #ubuntu\r\n");
			default:
				break;
		}

		//Recv &amp; print Data
		numbytes = recv(s,buf,MAXDATASIZE-1,0);
		buf[numbytes]='\0';
		cout &lt;&lt; buf;
		//buf is the data that is recived

		//Pass buf to the message handeler
		msgHandel(buf);

		//If Ping Recived
		/*
		 * must reply to ping overwise connection will be closed
		 * see http://www.irchelp.org/irchelp/rfc/chapter4.html
		 */
		if (charSearch(buf,"PING"))
		{
			sendPong(buf);
		}

		//break if connection closed
		if (numbytes==0)
		{
			cout &lt;&lt; "----------------------CONNECTION CLOSED---------------------------"&lt;&lt; endl;
			cout &lt;&lt; timeNow() &lt;&lt; endl;

			break;
		}
	}
}

bool IrcBot::charSearch(char *toSearch, char *searchFor)
{
	int len = strlen(toSearch);
	int forLen = strlen(searchFor); // The length of the searchfor field

	//Search through each char in toSearch
	for (int i = 0; i &lt; len;i++)
	{
		//If the active char is equil to the first search item then search toSearch
		if (searchFor[0] == toSearch[i])
		{
			bool found = true;
			//search the char array for search field
			for (int x = 1; x &lt; forLen; x++)
			{
				if (toSearch[i+x]!=searchFor[x])
				{
					found = false;
				}
			}

			//if found return true;
			if (found == true)
				return true;
		}
	}

	return 0;
}

bool IrcBot::isConnected(char *buf)
{//returns true if "/MOTD" is found in the input strin
	//If we find /MOTD then its ok join a channel
	if (charSearch(buf,"/MOTD") == true)
		return true;
	else
		return false;
}

char * IrcBot::timeNow()
{//returns the current date and time
	time_t rawtime;
	struct tm * timeinfo;

	time ( &amp;rawtime );
	timeinfo = localtime ( &amp;rawtime );

	return asctime (timeinfo);
}

bool IrcBot::sendData(char *msg)
{//Send some data
	//Send some data
	int len = strlen(msg);
	int bytes_sent = send(s,msg,len,0);

	if (bytes_sent == 0)
		return false;
	else
		return true;
}

void IrcBot::sendPong(char *buf)
{
	//Get the reply address
	//loop through bug and find the location of PING
	//Search through each char in toSearch

	char * toSearch = "PING ";

	for (int i = 0; i &lt; strlen(buf);i++)
		{
			//If the active char is equil to the first search item then search toSearch
			if (buf[i] == toSearch[0])
			{
				bool found = true;
				//search the char array for search field
				for (int x = 1; x &lt; 4; x++)
				{
					if (buf[i+x]!=toSearch[x])
					{
						found = false;
					}
				}

				//if found return true;
				if (found == true)
				{
					int count = 0;
					//Count the chars
					for (int x = (i+strlen(toSearch)); x &lt; strlen(buf);x++)
					{
						count++;
					}

					//Create the new char array
					char returnHost[count + 5];
					returnHost[0]='P';
					returnHost[1]='O';
					returnHost[2]='N';
					returnHost[3]='G';
					returnHost[4]=' ';

					count = 0;
					//set the hostname data
					for (int x = (i+strlen(toSearch)); x &lt; strlen(buf);x++)
					{
						returnHost[count+5]=buf[x];
						count++;
					}

					//send the pong
					if (sendData(returnHost))
					{
						cout &lt;&lt; timeNow() &lt;&lt;"  Ping Pong" &lt;&lt; endl;
					}

					return;
				}
			}
		}

}

void IrcBot::msgHandel(char * buf)
{
	/*
	 * TODO: add you code to respod to commands here
	 * the example below replys to the command hi scooby
	 */
	if (charSearch(buf,"hi scooby"))
	{
		sendData("PRIVMSG #ubuntu :hi, hows it going\r\n");
	}

}</pre>
<p><a href="http://www.the-tech-tutorial.com/wp-content/files/irc-bot.tar">DOWNLOAD SOURCE</a></p>
<p><center><br />
<script type="text/javascript">// <![CDATA[
 google_ad_client = "ca-pub-2094089617852812"; /* 2011 Bottom */ google_ad_slot = "5825267234"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">// <![CDATA[</p>
<p>// ]]&gt;</script></center></p>
<h6>NOTES</h6>
<p>To change the server you wish the <span>IRC bot</span> to connect to change “irc.ubuntu.com” to the desired server at line 57.</p>
<p>You can change which channel you the <span>IRC bot</span> to connect to by changing “#ubuntu” at line 97 to the desired channel, I know there are better ways then hard coding thease commands however I was rushed for time and just trying to create a simple base for a <span>IRC bot</span>, not a full featured bot.</p>
<p>The msgHandel() function at line 256 is where you&#8217;ll add your <span>message <span>handling code</span></span>, at the moment the bot will reply to any <span>command</span> with the words “hi scooby” in it with the reply “Hi, hows it going”. To add more simply copy the if statement at line 262 and substitute the “hi scooby” for the command. Then change “hi, hows it going” to the required reply. Remember that all messages sent must finish with “\r\n” otherwise the server will wait for more commands.</p>
<p>For more information on the messages used in the IRC Protocol goto <a href="http://www.irchelp.org/irchelp/rfc/chapter4.html">http://www.irchelp.org/irchelp/rfc/chapter4.html</a>.</p>
<p>Please remember that <span>IRC Bots</span> are banned by many <span>IRC</span> Servers so be careful not to get banned, if you want to test on your own <span>IRC</span> server I have a tutorial on how to setup your own IRC Server <a href="http://www.the-tech-tutorial.com/?p=709">here</a>. I haven&#8217;t tested this bot on a server setup following this tutorial so please comment if you have any difficulty here, thanks. I hope this comes in useful, and I apologize for the spelling mistakes in my comment&#8217;s I’m just too lazy to go through them all and correct.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="standard" count="" href="http://www.the-tech-tutorial.com/?p=1716"></g:plusone></div>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=Simple+C%2B%2B+IRC+Bot+Template+&amp;link=http://www.the-tech-tutorial.com/?p=1716&amp;notes=I%20searched%20the%20Internet%2C%20for%20quit%20a%20while%2C%20and%20I%20couldn%E2%80%99t%20find%20the%20source%20for%20a%20simple%20IRC%20bot%20in%20C%20plus%20plus%2C%20so%20I%20decided%20to%20write%20one%20using%20a%20TCP%20Stream%20Socket%20in%20C%2B%2B.%20It%20works%20by%20setting%20up%20a%20simple%20TCP%20Socket%20to%20a%20IRC%20server%20on%20port%206667.%20The%20IRC%20Bot%20then%20assigns%20a%20NICK%20to%20the%20connection%20and%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=Simple+C%2B%2B+IRC+Bot+Template+&amp;link=http://www.the-tech-tutorial.com/?p=1716&amp;notes=I%20searched%20the%20Internet%2C%20for%20quit%20a%20while%2C%20and%20I%20couldn%E2%80%99t%20find%20the%20source%20for%20a%20simple%20IRC%20bot%20in%20C%20plus%20plus%2C%20so%20I%20decided%20to%20write%20one%20using%20a%20TCP%20Stream%20Socket%20in%20C%2B%2B.%20It%20works%20by%20setting%20up%20a%20simple%20TCP%20Socket%20to%20a%20IRC%20server%20on%20port%206667.%20The%20IRC%20Bot%20then%20assigns%20a%20NICK%20to%20the%20connection%20and%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.shareaholic.com/api/share/?title=Simple+C%2B%2B+IRC+Bot+Template+&amp;link=http://www.the-tech-tutorial.com/?p=1716&amp;notes=I%20searched%20the%20Internet%2C%20for%20quit%20a%20while%2C%20and%20I%20couldn%E2%80%99t%20find%20the%20source%20for%20a%20simple%20IRC%20bot%20in%20C%20plus%20plus%2C%20so%20I%20decided%20to%20write%20one%20using%20a%20TCP%20Stream%20Socket%20in%20C%2B%2B.%20It%20works%20by%20setting%20up%20a%20simple%20TCP%20Socket%20to%20a%20IRC%20server%20on%20port%206667.%20The%20IRC%20Bot%20then%20assigns%20a%20NICK%20to%20the%20connection%20and%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=&amp;tags=&amp;ctype=" rel="nofollow" class="external" title=""></a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=Simple+C%2B%2B+IRC+Bot+Template+&amp;link=http://www.the-tech-tutorial.com/?p=1716&amp;notes=I%20searched%20the%20Internet%2C%20for%20quit%20a%20while%2C%20and%20I%20couldn%E2%80%99t%20find%20the%20source%20for%20a%20simple%20IRC%20bot%20in%20C%20plus%20plus%2C%20so%20I%20decided%20to%20write%20one%20using%20a%20TCP%20Stream%20Socket%20in%20C%2B%2B.%20It%20works%20by%20setting%20up%20a%20simple%20TCP%20Socket%20to%20a%20IRC%20server%20on%20port%206667.%20The%20IRC%20Bot%20then%20assigns%20a%20NICK%20to%20the%20connection%20and%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=Simple+C%2B%2B+IRC+Bot+Template+&amp;link=http://www.the-tech-tutorial.com/?p=1716&amp;notes=I%20searched%20the%20Internet%2C%20for%20quit%20a%20while%2C%20and%20I%20couldn%E2%80%99t%20find%20the%20source%20for%20a%20simple%20IRC%20bot%20in%20C%20plus%20plus%2C%20so%20I%20decided%20to%20write%20one%20using%20a%20TCP%20Stream%20Socket%20in%20C%2B%2B.%20It%20works%20by%20setting%20up%20a%20simple%20TCP%20Socket%20to%20a%20IRC%20server%20on%20port%206667.%20The%20IRC%20Bot%20then%20assigns%20a%20NICK%20to%20the%20connection%20and%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=Simple+C%2B%2B+IRC+Bot+Template+&amp;link=http://www.the-tech-tutorial.com/?p=1716&amp;notes=I%20searched%20the%20Internet%2C%20for%20quit%20a%20while%2C%20and%20I%20couldn%E2%80%99t%20find%20the%20source%20for%20a%20simple%20IRC%20bot%20in%20C%20plus%20plus%2C%20so%20I%20decided%20to%20write%20one%20using%20a%20TCP%20Stream%20Socket%20in%20C%2B%2B.%20It%20works%20by%20setting%20up%20a%20simple%20TCP%20Socket%20to%20a%20IRC%20server%20on%20port%206667.%20The%20IRC%20Bot%20then%20assigns%20a%20NICK%20to%20the%20connection%20and%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.shareaholic.com/api/share/?title=Simple+C%2B%2B+IRC+Bot+Template+&amp;link=http://www.the-tech-tutorial.com/?p=1716&amp;notes=I%20searched%20the%20Internet%2C%20for%20quit%20a%20while%2C%20and%20I%20couldn%E2%80%99t%20find%20the%20source%20for%20a%20simple%20IRC%20bot%20in%20C%20plus%20plus%2C%20so%20I%20decided%20to%20write%20one%20using%20a%20TCP%20Stream%20Socket%20in%20C%2B%2B.%20It%20works%20by%20setting%20up%20a%20simple%20TCP%20Socket%20to%20a%20IRC%20server%20on%20port%206667.%20The%20IRC%20Bot%20then%20assigns%20a%20NICK%20to%20the%20connection%20and%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=88&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="https://shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.the-tech-tutorial.com/?feed=rss2&#038;p=1716</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing and Configuring Nagios Ubuntu 11.04</title>
		<link>http://www.the-tech-tutorial.com/?p=1433</link>
		<comments>http://www.the-tech-tutorial.com/?p=1433#comments</comments>
		<pubDate>Mon, 18 Jul 2011 14:08:14 +0000</pubDate>
		<dc:creator>Tyler Allen</dc:creator>
				<category><![CDATA[Fix It]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[add host]]></category>
		<category><![CDATA[configure]]></category>
		<category><![CDATA[Easy]]></category>
		<category><![CDATA[Host]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[Setup]]></category>
		<category><![CDATA[Simple]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[ubuntu 11.04]]></category>

		<guid isPermaLink="false">http://www.the-tech-tutorial.com/?p=1433</guid>
		<description><![CDATA[Nagios is the Industry Standard Network Monitoring Engine. OK great so what’s that mean, well Nagios is a server that monitors your hosts and services and will inform you if something goes wrong and when it is fixed again. It can monitor network services, host resources and even network probes such as temperature and moisture. [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2010/07/nagios.jpg"><img class="alignleft size-full wp-image-394" title="Nagios" src="http://www.the-tech-tutorial.com/wp-content/uploads/2010/07/nagios.jpg" alt="Nagios Logo" width="160" height="129" /></a></p>
<p><a href="http://www.nagios.org/"><span>Nagios</span></a> is the <span>Industry Standard <span><span>Network Monitoring</span> Engine</span></span>. OK great so what’s that mean, well <span>Nagios</span> is a <span>server</span> that <span>monitors</span> your <span>hosts</span> and <span>services</span> and will inform you if something goes wrong and when it is fixed again. It can monitor network services, host resources and even network probes such as temperature and moisture.</p>
<p>These features as well as many more make <span>Nagios</span>, by far, the most complete <span>open-source</span> <span><span>Network Monitoring</span> tool</span> on the market, however with all these features comes complexity and <span>Nagios</span> has obviously been designed with the experienced Network Administrator in mind. But don&#8217;t worry too much, its not that difficult to learn as long as you take it one step at a time, and in today&#8217;s tutorial we&#8217;re going to look at the first step, actually getting it installed <span id="more-1433"></span></p>
<p>So let’s get started, the first thing we need to <span>install</span> in <span>LAMP</span> as this is the <span>base</span> in which runs, simply type in the following command in your terminal and follow the onscreen commands:</p>
<pre>sudo tasksel install <span>lamp-server</span></pre>
<p>For more information on <span>LAMP</span> you can view my complete <span>LAMP server</span> tutorial <a href="http://www.the-tech-tutorial.com/?p=229">here</a></p>
<p>Now we need to install <span>Nagios</span>, to do this type:</p>
<pre>sudo <span>apt-get install</span> -y <span>nagios3</span></pre>
<p>This will install and configure <span>Nagios</span> 3 along with any the required dependencies you don’t already have. It may ask for a few input parameters such as internet address and login password, just follow the onscreen guidelines and you should be fine.</p>
<p>If you have completed these stops correctly you should be able to view your <span>Nagios</span> dashboard by typing in the following in your web browser substituting [IP ADDR] for your servers IP address.</p>
<pre>http://[IP ADDR]/nagios3/</pre>
<p>You&#8217;ll need to enter a <span>username</span> and <span>password</span>. Your <span>username</span> will be <em>&#8216;nagiosadmin&#8217;</em>, the password will be the same as the one you entered during setup.</p>
<p><strong>Username:</strong><em>nagiosadmin</em><br />
<strong>Password:</strong><em>entered during setup</em><br />
<center><br />
<script type="text/javascript"><!--
google_ad_client = "ca-pub-2094089617852812";
/* 2011 Bottom */
google_ad_slot = "5825267234";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center></p>
<h4><span><span>Add hosts</span> to your <span><span>Nagios</span> <span>Server</span></span></span></h4>
<p>No you have <span>Nagios</span> up and running you should be able to see your current server stats, (if not click on &#8220;Services&#8221; on the left side of the Nagios dashboard), but what if you want to add <span>more hosts</span>. Well it’s a little complicated at first but once you get used to it you&#8217;ll be fine. First we need to edit some <span>config files</span> to tell <span><span>Nagios</span> to <span>monitor</span> a new <span>host</span></span>, below is a diagram of all the Nagios config files:</p>
<p><center><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/07/nagios-config.png"><img class="size-full wp-image-1455 aligncenter" title="Nagios-config" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/07/nagios-config.png" alt="" width="550" height="387" /></a></center><br />
As we can see from this diagram every setting for <span>Nagios</span> is stored in a <span><span>config</span> file</span>, most of these can be found in your /etc/nagios3/conf.d folder. To add some new hosts we need to add some lines to your <span><em>/etc/nagios3/conf.d/localhost_nagios2.cfg</em></span> file. First off we are only going to be <span>adding new hosts</span>, not services (see my <a href="http://www.the-tech-tutorial.com/?p=816">NRPE tutorial</a> if you want to monitor services aswell), so we only need add a small amount of code. The <span>local <span>host <span>definition</span></span></span> in your <span>/etc/nagios3/conf.d/localhost_nagios2.cfg</span> should look like this:</p>
<pre>
define host{
        use                     generic-host            ; Name of host template to use
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        }
</pre>
<div style="width:350px; height:330px;background-image: url(http://www.the-tech-tutorial.com/wp-content/uploads/2011/03/add_back1.png); display: block; float: right; padding: 20px 25px 0px 30px;">
<script type="text/javascript"><!--
google_ad_client = "pub-2094089617852812";
/* 2011 In Text Box */
google_ad_slot = "1777411765";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>Here we can see then the <span>template</span> is <span>generic-host</span>, the <span>hostname</span> and <span>alias</span> are set to localhost(127.0.0.1) and the <span>address</span> is set to 127.0.0.1. The use filed is important as if you enter a name here that doesn’t correspond to a template then <span>Nagios</span> will fail to start. The <span>address</span> field is also important, this is where you put the actual address for the server you want to <span>monitor</span> (either <span>domain name</span> or <span>IP</span> will work here). The <span>host_name and alies fields</span> are not as important and are only there to help the user <span>distinguish between <span>hosts</span></span>. The difference between the two is <span>host_name</span> is read internally (so <strong>don&#8217;t</strong> use spaces or special characters) and alias is actually show to the user (you <strong>can</strong> use spaces and special characters).</p>
<p>So now it’s time to <span>add your own host</span> to your <span><span>Nagios</span> server</span>, in this example we are going to add www.google.com as your <span>new host</span>, if you want you can subtitle your own attributes however I like to have Google as a host just to ensure my setup is correct. So start your favourite text editor and add the hollowing lines to the end of your <strong>/etc/nagios3/conf.d/localhost_nagios2.cfg</strong></p>
<pre>define host{
        use                     generic-host            ; Name of host template to use
        host_name               google
        alias                   Google
        address                 www.google.com
        }</pre>
<p>to see the changes on your dashboard you need to restart Nagios, type:</p>
<pre>sudo /etc/init.d/nagios3 restart</pre>
<p>Now if you want to add your own hosts to your Nagios server repeat the last two steps substituting host_name, alias and address to your hosts details and restart Nagios to see the changes.</p>
<p>Please leave any comments or questions, thanks.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="standard" count="" href="http://www.the-tech-tutorial.com/?p=1433"></g:plusone></div>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+and+Configuring+Nagios+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1433&amp;notes=%0D%0A%0D%0ANagios%20is%20the%20Industry%20Standard%20Network%20Monitoring%20Engine.%20OK%20great%20so%20what%E2%80%99s%20that%20mean%2C%20well%20Nagios%20is%20a%20server%20that%20monitors%20your%20hosts%20and%20services%20and%20will%20inform%20you%20if%20something%20goes%20wrong%20and%20when%20it%20is%20fixed%20again.%20It%20can%20monitor%20network%20services%2C%20host%20resources%20and%20even%20network%20probes&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+and+Configuring+Nagios+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1433&amp;notes=%0D%0A%0D%0ANagios%20is%20the%20Industry%20Standard%20Network%20Monitoring%20Engine.%20OK%20great%20so%20what%E2%80%99s%20that%20mean%2C%20well%20Nagios%20is%20a%20server%20that%20monitors%20your%20hosts%20and%20services%20and%20will%20inform%20you%20if%20something%20goes%20wrong%20and%20when%20it%20is%20fixed%20again.%20It%20can%20monitor%20network%20services%2C%20host%20resources%20and%20even%20network%20probes&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+and+Configuring+Nagios+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1433&amp;notes=%0D%0A%0D%0ANagios%20is%20the%20Industry%20Standard%20Network%20Monitoring%20Engine.%20OK%20great%20so%20what%E2%80%99s%20that%20mean%2C%20well%20Nagios%20is%20a%20server%20that%20monitors%20your%20hosts%20and%20services%20and%20will%20inform%20you%20if%20something%20goes%20wrong%20and%20when%20it%20is%20fixed%20again.%20It%20can%20monitor%20network%20services%2C%20host%20resources%20and%20even%20network%20probes&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=&amp;tags=&amp;ctype=" rel="nofollow" class="external" title=""></a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+and+Configuring+Nagios+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1433&amp;notes=%0D%0A%0D%0ANagios%20is%20the%20Industry%20Standard%20Network%20Monitoring%20Engine.%20OK%20great%20so%20what%E2%80%99s%20that%20mean%2C%20well%20Nagios%20is%20a%20server%20that%20monitors%20your%20hosts%20and%20services%20and%20will%20inform%20you%20if%20something%20goes%20wrong%20and%20when%20it%20is%20fixed%20again.%20It%20can%20monitor%20network%20services%2C%20host%20resources%20and%20even%20network%20probes&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+and+Configuring+Nagios+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1433&amp;notes=%0D%0A%0D%0ANagios%20is%20the%20Industry%20Standard%20Network%20Monitoring%20Engine.%20OK%20great%20so%20what%E2%80%99s%20that%20mean%2C%20well%20Nagios%20is%20a%20server%20that%20monitors%20your%20hosts%20and%20services%20and%20will%20inform%20you%20if%20something%20goes%20wrong%20and%20when%20it%20is%20fixed%20again.%20It%20can%20monitor%20network%20services%2C%20host%20resources%20and%20even%20network%20probes&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+and+Configuring+Nagios+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1433&amp;notes=%0D%0A%0D%0ANagios%20is%20the%20Industry%20Standard%20Network%20Monitoring%20Engine.%20OK%20great%20so%20what%E2%80%99s%20that%20mean%2C%20well%20Nagios%20is%20a%20server%20that%20monitors%20your%20hosts%20and%20services%20and%20will%20inform%20you%20if%20something%20goes%20wrong%20and%20when%20it%20is%20fixed%20again.%20It%20can%20monitor%20network%20services%2C%20host%20resources%20and%20even%20network%20probes&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.shareaholic.com/api/share/?title=Installing+and+Configuring+Nagios+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1433&amp;notes=%0D%0A%0D%0ANagios%20is%20the%20Industry%20Standard%20Network%20Monitoring%20Engine.%20OK%20great%20so%20what%E2%80%99s%20that%20mean%2C%20well%20Nagios%20is%20a%20server%20that%20monitors%20your%20hosts%20and%20services%20and%20will%20inform%20you%20if%20something%20goes%20wrong%20and%20when%20it%20is%20fixed%20again.%20It%20can%20monitor%20network%20services%2C%20host%20resources%20and%20even%20network%20probes&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=88&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="https://shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.the-tech-tutorial.com/?feed=rss2&#038;p=1433</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CPU Limit Ubuntu Server 11.04 Command Line</title>
		<link>http://www.the-tech-tutorial.com/?p=1488</link>
		<comments>http://www.the-tech-tutorial.com/?p=1488#comments</comments>
		<pubDate>Mon, 11 Jul 2011 14:33:33 +0000</pubDate>
		<dc:creator>Tyler Allen</dc:creator>
				<category><![CDATA[Short]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[11.04]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.the-tech-tutorial.com/?p=1488</guid>
		<description><![CDATA[I’ve was encrypting some files the other day with GPG and found that while the encryption was taking place my computer ground to a halt because GPG was taking up all of my CPU. Normally I wouldn’t mind this as I would just setup a few jobs and go make a cup of tea. Then [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/07/CPU-Limit.jpg"><img class="alignleft size-full wp-image-1492" title="CPU-Limit" src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/07/CPU-Limit.jpg" alt="" width="100" height="100" /></a>I’ve was encrypting some files the other day with GPG and found that while the encryption was taking place my computer ground to a halt because GPG was taking up all of my <span>CPU</span>. Normally I wouldn’t mind this as I would just setup a few jobs and go make a cup of tea. Then I though what would happen if I run my encryption jobs on a <span>webserver</span>, well it grinds to a halt. So how do we run encryption jobs on our servers without affecting users,<span id="more-1488"></span>well first off we could just by a <span>multi core processor</span> and put it in your, server that&#8217;s the fastest way of fixing the problems. However if you’re like me, <span> lazy</span>, then you can use a tool called <span><span>CPU</span> limit</span>, to <span>limit</span> the amount of a single <span>CPU</span> a <span>process</span> can run, to get started just type:</p>
<p><center><br />
<script type="text/javascript">// <![CDATA[
 google_ad_client = "ca-pub-2094089617852812"; /* 2011 Bottom */ google_ad_slot = "5825267234"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">// <![CDATA[</p>
<p>// ]]&gt;</script></center></p>
<pre>Sudo apt-get install cpulimit</pre>
<p>Once <span>cpulimit</span> is installed all you need to do is run the program you want to <span>limit</span> then type the following substituting [program] to the program you want to run, <em>i.e gpg</em>:</p>
<pre>sudo cpulimit -e "[program]" -l 30</pre>
<p><center><br />
<script type="text/javascript">// <![CDATA[
 google_ad_client = "ca-pub-2094089617852812"; /* 2011 Bottom */ google_ad_slot = "5825267234"; google_ad_width = 468; google_ad_height = 60;
// ]]&gt;</script><br />
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">// <![CDATA[</p>
<p>// ]]&gt;</script></center><br />
And that’s about it, cpulimit will throttle your chosen program to 30% CPU usage.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="standard" count="" href="http://www.the-tech-tutorial.com/?p=1488"></g:plusone></div>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=CPU+Limit+Ubuntu+Server+11.04+Command+Line&amp;link=http://www.the-tech-tutorial.com/?p=1488&amp;notes=I%E2%80%99ve%20was%20encrypting%20some%20files%20the%20other%20day%20with%20GPG%20and%20found%20that%20while%20the%20encryption%20was%20taking%20place%20my%20computer%20ground%20to%20a%20halt%20because%20GPG%20was%20taking%20up%20all%20of%20my%20CPU.%20Normally%20I%20wouldn%E2%80%99t%20mind%20this%20as%20I%20would%20just%20setup%20a%20few%20jobs%20and%20go%20make%20a%20cup%20of%20tea.%20Then%20I%20though%20what%20would%20happe&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=CPU+Limit+Ubuntu+Server+11.04+Command+Line&amp;link=http://www.the-tech-tutorial.com/?p=1488&amp;notes=I%E2%80%99ve%20was%20encrypting%20some%20files%20the%20other%20day%20with%20GPG%20and%20found%20that%20while%20the%20encryption%20was%20taking%20place%20my%20computer%20ground%20to%20a%20halt%20because%20GPG%20was%20taking%20up%20all%20of%20my%20CPU.%20Normally%20I%20wouldn%E2%80%99t%20mind%20this%20as%20I%20would%20just%20setup%20a%20few%20jobs%20and%20go%20make%20a%20cup%20of%20tea.%20Then%20I%20though%20what%20would%20happe&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.shareaholic.com/api/share/?title=CPU+Limit+Ubuntu+Server+11.04+Command+Line&amp;link=http://www.the-tech-tutorial.com/?p=1488&amp;notes=I%E2%80%99ve%20was%20encrypting%20some%20files%20the%20other%20day%20with%20GPG%20and%20found%20that%20while%20the%20encryption%20was%20taking%20place%20my%20computer%20ground%20to%20a%20halt%20because%20GPG%20was%20taking%20up%20all%20of%20my%20CPU.%20Normally%20I%20wouldn%E2%80%99t%20mind%20this%20as%20I%20would%20just%20setup%20a%20few%20jobs%20and%20go%20make%20a%20cup%20of%20tea.%20Then%20I%20though%20what%20would%20happe&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=&amp;tags=&amp;ctype=" rel="nofollow" class="external" title=""></a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=CPU+Limit+Ubuntu+Server+11.04+Command+Line&amp;link=http://www.the-tech-tutorial.com/?p=1488&amp;notes=I%E2%80%99ve%20was%20encrypting%20some%20files%20the%20other%20day%20with%20GPG%20and%20found%20that%20while%20the%20encryption%20was%20taking%20place%20my%20computer%20ground%20to%20a%20halt%20because%20GPG%20was%20taking%20up%20all%20of%20my%20CPU.%20Normally%20I%20wouldn%E2%80%99t%20mind%20this%20as%20I%20would%20just%20setup%20a%20few%20jobs%20and%20go%20make%20a%20cup%20of%20tea.%20Then%20I%20though%20what%20would%20happe&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=CPU+Limit+Ubuntu+Server+11.04+Command+Line&amp;link=http://www.the-tech-tutorial.com/?p=1488&amp;notes=I%E2%80%99ve%20was%20encrypting%20some%20files%20the%20other%20day%20with%20GPG%20and%20found%20that%20while%20the%20encryption%20was%20taking%20place%20my%20computer%20ground%20to%20a%20halt%20because%20GPG%20was%20taking%20up%20all%20of%20my%20CPU.%20Normally%20I%20wouldn%E2%80%99t%20mind%20this%20as%20I%20would%20just%20setup%20a%20few%20jobs%20and%20go%20make%20a%20cup%20of%20tea.%20Then%20I%20though%20what%20would%20happe&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=CPU+Limit+Ubuntu+Server+11.04+Command+Line&amp;link=http://www.the-tech-tutorial.com/?p=1488&amp;notes=I%E2%80%99ve%20was%20encrypting%20some%20files%20the%20other%20day%20with%20GPG%20and%20found%20that%20while%20the%20encryption%20was%20taking%20place%20my%20computer%20ground%20to%20a%20halt%20because%20GPG%20was%20taking%20up%20all%20of%20my%20CPU.%20Normally%20I%20wouldn%E2%80%99t%20mind%20this%20as%20I%20would%20just%20setup%20a%20few%20jobs%20and%20go%20make%20a%20cup%20of%20tea.%20Then%20I%20though%20what%20would%20happe&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.shareaholic.com/api/share/?title=CPU+Limit+Ubuntu+Server+11.04+Command+Line&amp;link=http://www.the-tech-tutorial.com/?p=1488&amp;notes=I%E2%80%99ve%20was%20encrypting%20some%20files%20the%20other%20day%20with%20GPG%20and%20found%20that%20while%20the%20encryption%20was%20taking%20place%20my%20computer%20ground%20to%20a%20halt%20because%20GPG%20was%20taking%20up%20all%20of%20my%20CPU.%20Normally%20I%20wouldn%E2%80%99t%20mind%20this%20as%20I%20would%20just%20setup%20a%20few%20jobs%20and%20go%20make%20a%20cup%20of%20tea.%20Then%20I%20though%20what%20would%20happe&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=88&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="https://shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.the-tech-tutorial.com/?feed=rss2&#038;p=1488</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up FTP for your website Ubuntu 11.04</title>
		<link>http://www.the-tech-tutorial.com/?p=1467</link>
		<comments>http://www.the-tech-tutorial.com/?p=1467#comments</comments>
		<pubDate>Thu, 07 Jul 2011 15:34:16 +0000</pubDate>
		<dc:creator>Tyler Allen</dc:creator>
				<category><![CDATA[Fix It]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[/var/www]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Easy]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[ftp configure]]></category>
		<category><![CDATA[ftp setup]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[ubuntu 11.04]]></category>
		<category><![CDATA[wesbite]]></category>

		<guid isPermaLink="false">http://www.the-tech-tutorial.com/?p=1467</guid>
		<description><![CDATA[File Transfer Protocol (FTP) is a standard network protocol used to transfer files from one host to another over a TCP-based network, such as the Internet. Its most common use is uploading your website files to your webserver, allowing you to develop your website, upload it via FTP then refresh the page to see the [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.the-tech-tutorial.com/wp-content/uploads/2011/07/j0409355_278799_7.png"><img src="http://www.the-tech-tutorial.com/wp-content/uploads/2011/07/j0409355_278799_7.png" alt="" title="Transfer_Vis" width="100" height="100" class="alignleft size-full wp-image-1480" /></a>File Transfer Protocol (<span>FTP</span>) is a standard <a href="http://en.wikipedia.org/wiki/Network_protocol">network protocol</a> used to transfer files from one host to another over a TCP-based network, such as the Internet. Its most common use is uploading your <span>website</span> files to your <span>webserver</span>, allowing you to develop your <span>website</span>, upload it via <span>FTP</span> then refresh the page to see the updated page. If you’re setting up your own <span>webserver</span>s its essential you have some way of uploading files and the best way to do this is with <span>FTP</span>. First you need to setup and configure an <span>ftp</span> server on your <span>webserver</span>, in this tutorial we are going to be using <span>Pro<span>FTP</span></span>. <span>Pro<span>FTP</span></span>D is a proven, high-performance and scalable <span>FTP</span> server, with a focus toward simplicity, security, and ease of configuration.<span id="more-1467"></span></p>
<div style="width:350px; height:300px;background-image: url(http://www.the-tech-tutorial.com/wp-content/uploads/2011/03/add_back1.png); display: block; float: right; padding: 20px 25px 0px 30px;">
<script type="text/javascript"><!--
google_ad_client = "pub-2094089617852812";
/* 2011 In Text Box */
google_ad_slot = "1777411765";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>I’ve gone through many <span>FTP</span> server tutorials in the past and they all work fine for uploading to your home directory but in this situation we <span>don’t want to just upload to our <span>home directors</span></span>, we want <span><span>to upload to our <span>website</span></span> directors</span>, in this case <span>/var/wwwr</span>. First off we need to setup a new <span>user</span> for our <span>ftp</span> <span>login</span> details:</p>
<pre>
sudo <span>user</span>add [<span>user</span>name]
sudo passwd [<span>user</span>name]
</pre>
<p>Now we need to add the <span>www-data</span> group so it can write to you <span>webserver</span> storage, be warned this will set the <span>user</span>s primary group to <span>www-data</span> so ensure you have created a new <span>user</span> especially for use as an <span>ftp</span> account.</p>
<pre>
sudo <span>user</span>mod  -g <span>www-data</span> [<span>user</span>name]
</pre>
<p>Now in most situations your <span>website</span> is stored in <span>/var/wwwr</span>, this often restricts writing from the <span>www-data</span> group so we need to change the permissions to allow any <span>user</span> in the <span>www-data</span> group to write to the <span>/var/wwwr</span> folder:</p>
<pre>
sudo chmod -R g+w <span>/var/wwwr</span>
</pre>
<p>Now we are ready to actually install the server, simply type:</p>
<pre>
sudo apt-get install pro<span>ftp</span>d
</pre>
<p>and select the Stand Alone option when asked. Now we need to make some small configuration changes to<br />
<center><br />
<script type="text/javascript"><!--
google_ad_client = "ca-pub-2094089617852812";
/* 2011 Bottom */
google_ad_slot = "5825267234";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center><br />
<span>Pro<span>FTP</span></span>, first open then pro<span>ftp</span>d.conf file:</p>
<pre>
sudo nano /etc/pro<span>ftp</span>d/pro<span>ftp</span>d.conf
</pre>
<p>and edit the following lines to match my example,</p>
<pre>
# Use this to jail all <span>user</span>s in their homes
DefaultRoot                     <span>/var/wwwr</span>
# Set the <span>user</span> and group that the server normally runs at.
User                            <span>www-data</span>
Group                           <span>www-data</span>
</pre>
<p>Now we need to restart <span>Pro<span>FTP</span></span> so that it recognises the new settings:</p>
<pre> 
sudo /etc/init.d/pro<span>ftp</span>d restart
</pre>
<p>and thats it your <span>ftp</span> server should be setup to allow you to upload, edit and download your <span>website</span>, to test this simply type in:</p>
<pre><span>ftp</span> 127.0.0.1</pre>
<p>and enter your login details, now try making a folder with the following command</p>
<pre>mkdir test</pre>
<p>if you can do this with no errors that your <span>ftp</span> server has been correctly configured.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="standard" count="" href="http://www.the-tech-tutorial.com/?p=1467"></g:plusone></div>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=Setting+up+FTP+for+your+website+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1467&amp;notes=File%20Transfer%20Protocol%20%28FTP%29%20is%20a%20standard%20network%20protocol%20used%20to%20transfer%20files%20from%20one%20host%20to%20another%20over%20a%20TCP-based%20network%2C%20such%20as%20the%20Internet.%20Its%20most%20common%20use%20is%20uploading%20your%20website%20files%20to%20your%20webserver%2C%20allowing%20you%20to%20develop%20your%20website%2C%20upload%20it%20via%20FTP%20then%20refresh%20the%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=Setting+up+FTP+for+your+website+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1467&amp;notes=File%20Transfer%20Protocol%20%28FTP%29%20is%20a%20standard%20network%20protocol%20used%20to%20transfer%20files%20from%20one%20host%20to%20another%20over%20a%20TCP-based%20network%2C%20such%20as%20the%20Internet.%20Its%20most%20common%20use%20is%20uploading%20your%20website%20files%20to%20your%20webserver%2C%20allowing%20you%20to%20develop%20your%20website%2C%20upload%20it%20via%20FTP%20then%20refresh%20the%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.shareaholic.com/api/share/?title=Setting+up+FTP+for+your+website+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1467&amp;notes=File%20Transfer%20Protocol%20%28FTP%29%20is%20a%20standard%20network%20protocol%20used%20to%20transfer%20files%20from%20one%20host%20to%20another%20over%20a%20TCP-based%20network%2C%20such%20as%20the%20Internet.%20Its%20most%20common%20use%20is%20uploading%20your%20website%20files%20to%20your%20webserver%2C%20allowing%20you%20to%20develop%20your%20website%2C%20upload%20it%20via%20FTP%20then%20refresh%20the%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=&amp;tags=&amp;ctype=" rel="nofollow" class="external" title=""></a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=Setting+up+FTP+for+your+website+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1467&amp;notes=File%20Transfer%20Protocol%20%28FTP%29%20is%20a%20standard%20network%20protocol%20used%20to%20transfer%20files%20from%20one%20host%20to%20another%20over%20a%20TCP-based%20network%2C%20such%20as%20the%20Internet.%20Its%20most%20common%20use%20is%20uploading%20your%20website%20files%20to%20your%20webserver%2C%20allowing%20you%20to%20develop%20your%20website%2C%20upload%20it%20via%20FTP%20then%20refresh%20the%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=Setting+up+FTP+for+your+website+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1467&amp;notes=File%20Transfer%20Protocol%20%28FTP%29%20is%20a%20standard%20network%20protocol%20used%20to%20transfer%20files%20from%20one%20host%20to%20another%20over%20a%20TCP-based%20network%2C%20such%20as%20the%20Internet.%20Its%20most%20common%20use%20is%20uploading%20your%20website%20files%20to%20your%20webserver%2C%20allowing%20you%20to%20develop%20your%20website%2C%20upload%20it%20via%20FTP%20then%20refresh%20the%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=Setting+up+FTP+for+your+website+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1467&amp;notes=File%20Transfer%20Protocol%20%28FTP%29%20is%20a%20standard%20network%20protocol%20used%20to%20transfer%20files%20from%20one%20host%20to%20another%20over%20a%20TCP-based%20network%2C%20such%20as%20the%20Internet.%20Its%20most%20common%20use%20is%20uploading%20your%20website%20files%20to%20your%20webserver%2C%20allowing%20you%20to%20develop%20your%20website%2C%20upload%20it%20via%20FTP%20then%20refresh%20the%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.shareaholic.com/api/share/?title=Setting+up+FTP+for+your+website+Ubuntu+11.04&amp;link=http://www.the-tech-tutorial.com/?p=1467&amp;notes=File%20Transfer%20Protocol%20%28FTP%29%20is%20a%20standard%20network%20protocol%20used%20to%20transfer%20files%20from%20one%20host%20to%20another%20over%20a%20TCP-based%20network%2C%20such%20as%20the%20Internet.%20Its%20most%20common%20use%20is%20uploading%20your%20website%20files%20to%20your%20webserver%2C%20allowing%20you%20to%20develop%20your%20website%2C%20upload%20it%20via%20FTP%20then%20refresh%20the%20&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=88&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="https://shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.the-tech-tutorial.com/?feed=rss2&#038;p=1467</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nagios Memeory Check Plugin &#8211; download &amp; install</title>
		<link>http://www.the-tech-tutorial.com/?p=1435</link>
		<comments>http://www.the-tech-tutorial.com/?p=1435#comments</comments>
		<pubDate>Wed, 06 Jul 2011 14:11:17 +0000</pubDate>
		<dc:creator>Tyler Allen</dc:creator>
				<category><![CDATA[Fix It]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[11.04]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[Easy]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[memory plugin]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[nagios 3]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.the-tech-tutorial.com/?p=1435</guid>
		<description><![CDATA[When I noticed that Nagios had no memory check plugin I decided to make a simple bash plugin for Nagios to check how much memory my machines were using. It works by reading /proc/meminfo so it should work on every system were you can read /proc/meminfo (most Linux and Unix based systems) This plugin is [...]]]></description>
				<content:encoded><![CDATA[<p>When I noticed that <span>Nagios</span> had <span><span>no <span><span>memory check</span></span></span> <span>plugin</span></span> I decided to make a <span>simple bash <span><span>plugin</span></span> for <span>Nagios</span></span> to check how much <span>memory</span> my machines were <span>using</span>. It works by reading <span>/proc/meminfo</span> so it should work on every system were you can <span>read /proc/meminfo</span> (most Linux and Unix based systems)<span id="more-1435"></span><br />
This <span>plugin</span> is released under the terms of the GPLv2 so please feel free to edit it as needed, you can <span>download</span> it from <a href="http://www.the-tech-tutorial.com/wp-content/files/chk_mem.sh">here</a>. If you haven’t installed a plugin for Nagios before I’ll go through a simple <span>tutorial</span> now. First <span>download</span> this plugin with the below link or copy the below code to your <span><span>Nagios</span> <span>plugin</span></span> directory <em>(<span><span><span>Ubuntu</span> 11.04</span> location</span>: /usr/lib/<span>nagios</span>/<span>plugins</span>/)</em><br />
<center><br />
<script type="text/javascript"><!--
google_ad_client = "ca-pub-2094089617852812";
/* 2011 Bottom */
google_ad_slot = "5825267234";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center><br />
<a href="http://www.the-tech-tutorial.com/wp-content/files/chk_mem.sh">Download Plugin</a></p>
<pre>
#!/bin/bash

#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; version 2 of the License only.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

PROGNAME=`basename $0`
VERSION="Version 1.0"
AUTHOR="2011, Tyler Allen (http://www.the-tech-tutorial.com/)"

LV_W=100;
LV_C=100;


#Print Version
print_version() {
    echo "$VERSION $AUTHOR"
}

#Print Help
usage(){
        echo $PROGNAME $VERSION
        echo $AUTHOR
        echo
        echo This is a Nagios plugin that will check the curremt memory usage of the system.
        echo
        echo OPTIONS:
        echo  -h Shows this help
        echo  -v Shows the Version
        echo  -w sets the warning level
        echo  -c sets the critical level
}

#Parmature Getter
while getopts "hvw:c:" opt; do
  case $opt in
    h)
      usage
      exit
      ;;
    v)
      print_version
      exit
      ;;
    w)
      LV_W=$OPTARG
      ;;
    c)
      LV_C=$OPTARG
      ;;

    \?)
      echo "Invalid option: -$OPTARG" >&#038;2
      exit 1
      ;;
    <img src='http://www.the-tech-tutorial.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> 
      echo "Option -$OPTARG requires an argument." >&#038;2
      exit 1
      ;;
  esac
done

#Check the diffrence between the LV values
    if [ ${LV_W} -gt ${LV_C} ]
    then
        echo "Please adjust levels. The critical level must be higher than the warning level!"
        exit 666
    fi

#Values must be between 0 and 100
    if [ "$LV_W" -lt 0 -o "$LV_W" -gt 100 -o "$LV_C" -lt 0 -o "$LV_C" -gt 100 ]
    then
        echo "Warning and critical level values must be between 0 and 100."
        exit 666
    fi

#Get the figures
MEM_TOTAL=`grep "^MemTotal" /proc/meminfo|awk '{print $2}'`
TMP_MEM_FREE=`grep "^MemFree" /proc/meminfo|awk '{print $2}'`
TMP_MEM_USED=`expr $MEM_TOTAL - $TMP_MEM_FREE`
BUFFERS=`grep "^Buffers" /proc/meminfo|awk '{print $2}'`
CACHED=`grep "^Cached" /proc/meminfo|awk '{print $2}'`

P_MEM_FREE=`echo "scale=2; $TMP_MEM_FREE / $MEM_TOTAL * 100" | bc -l | sed 's/.[0-9][0-9]//'`
P_MEM_USED=`echo "scale=0; 100 - $P_MEM_FREE" | bc -l`

if [ ! -z "$LV_W" -a ! -z "$LV_C" ]
    then
        if [ ${P_MEM_USED} -ge ${LV_W} -a ${P_MEM_USED} -lt ${LV_C} ]
        then
            echo "WARNING - Used: $P_MEM_USED%, Free: $P_MEM_FREE% | 'mem_used'=$P_MEM_USED;$LV_W;$LV_C 'mem_free'=$P_MEM_FREE"
            exit $ST_WR
        elif [ ${P_MEM_USED} -ge ${LV_C} ]
        then
            echo "CRITICAL - Used: $P_MEM_USED%, Free: $P_MEM_FREE% | 'mem_used'=$P_MEM_USED;$LV_W;$LV_C 'mem_free'=$P_MEM_FREE"
            exit $ST_CR
        else
            echo "OK - Used: $P_MEM_USED%, Free: $P_MEM_FREE% | 'mem_used'=$P_MEM_USED;$LV_W;$LV_C 'mem_free'=$P_MEM_FREE"
            exit $ST_OK
        fi
    else
            echo "OK - Used: $P_MEM_USED%, Free: $P_MEM_FREE% | 'mem_used'=$P_MEM_USED 'mem_free'=$P_MEM_FREE"
            exit $ST_OK
    fi
</pre>
<p>Now you have saved this in your <span>plugin</span> folder we need to <span>configure <span>Nagios</span></span> to read the new <span>plugin</span>, to do this we need to add some information to the <span>commands.cfg</span> file <em>(<span><span><span>Ubuntu</span> 11.04</span> location</span>: /etc/nagios3/commands.cfg)</em>. Once you’ve opened the file add the following lines:<br />
<center><br />
<script type="text/javascript"><!--
google_ad_client = "ca-pub-2094089617852812";
/* 2011 Bottom */
google_ad_slot = "5825267234";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></center></p>
<pre>
#Memory Check Plugin command definition
define command {
        command_name chk_mem
        command_line /usr/lib/nagios/plugins/chk_mem.sh -w '$ARG1$' -c '$ARG2$'
}
</pre>
<p>Now we need to add the new <span>command</span> to a <span><span>service</span>s</span> attached to a host, first add the following lines to your <span>services</span> <span><span>config</span> file</span>, for this example I am only going to <span>add this service to the <span>local host</span></span> monitor <em>(<span><span><span>Ubuntu</span> 11.04</span> <span>location</span></span>: /etc/nagios3/conf.d/localhost_nagios2.cfg)</em></p>
<pre>
#Define a service to check how much memory the system has left
#warning if >70% used critical if >90% used
define service{
        use generic-service         ; Name of service template to use
        host_name                   localhost
        service_description         Memory Use
        check_command               chk_mem!75%!90%
}
</pre>
<p>Now all you need to do is <span>restart <span>Nagios</span></span> and you should see your new <span>plugin</span> in action.</p>
<pre>sudo /etc/init.d/nagios3 restart</pre>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="standard" count="" href="http://www.the-tech-tutorial.com/?p=1435"></g:plusone></div>

<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-digg">
			<a href="http://www.shareaholic.com/api/share/?title=Nagios+Memeory+Check+Plugin+-+download+%26+install&amp;link=http://www.the-tech-tutorial.com/?p=1435&amp;notes=When%20I%20noticed%20that%20Nagios%20had%20no%20memory%20check%20plugin%20I%20decided%20to%20make%20a%20simple%20bash%20plugin%20for%20Nagios%20to%20check%20how%20much%20memory%20my%20machines%20were%20using.%20It%20works%20by%20reading%20%2Fproc%2Fmeminfo%20so%20it%20should%20work%20on%20every%20system%20were%20you%20can%20read%20%2Fproc%2Fmeminfo%20%28most%20Linux%20and%20Unix%20based%20systems%29%0D%0AThis%20plugi&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=3&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.shareaholic.com/api/share/?title=Nagios+Memeory+Check+Plugin+-+download+%26+install&amp;link=http://www.the-tech-tutorial.com/?p=1435&amp;notes=When%20I%20noticed%20that%20Nagios%20had%20no%20memory%20check%20plugin%20I%20decided%20to%20make%20a%20simple%20bash%20plugin%20for%20Nagios%20to%20check%20how%20much%20memory%20my%20machines%20were%20using.%20It%20works%20by%20reading%20%2Fproc%2Fmeminfo%20so%20it%20should%20work%20on%20every%20system%20were%20you%20can%20read%20%2Fproc%2Fmeminfo%20%28most%20Linux%20and%20Unix%20based%20systems%29%0D%0AThis%20plugi&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=5&amp;tags=&amp;ctype=" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.shareaholic.com/api/share/?title=Nagios+Memeory+Check+Plugin+-+download+%26+install&amp;link=http://www.the-tech-tutorial.com/?p=1435&amp;notes=When%20I%20noticed%20that%20Nagios%20had%20no%20memory%20check%20plugin%20I%20decided%20to%20make%20a%20simple%20bash%20plugin%20for%20Nagios%20to%20check%20how%20much%20memory%20my%20machines%20were%20using.%20It%20works%20by%20reading%20%2Fproc%2Fmeminfo%20so%20it%20should%20work%20on%20every%20system%20were%20you%20can%20read%20%2Fproc%2Fmeminfo%20%28most%20Linux%20and%20Unix%20based%20systems%29%0D%0AThis%20plugi&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=&amp;tags=&amp;ctype=" rel="nofollow" class="external" title=""></a>
		</li>
		<li class="shr-reddit">
			<a href="http://www.shareaholic.com/api/share/?title=Nagios+Memeory+Check+Plugin+-+download+%26+install&amp;link=http://www.the-tech-tutorial.com/?p=1435&amp;notes=When%20I%20noticed%20that%20Nagios%20had%20no%20memory%20check%20plugin%20I%20decided%20to%20make%20a%20simple%20bash%20plugin%20for%20Nagios%20to%20check%20how%20much%20memory%20my%20machines%20were%20using.%20It%20works%20by%20reading%20%2Fproc%2Fmeminfo%20so%20it%20should%20work%20on%20every%20system%20were%20you%20can%20read%20%2Fproc%2Fmeminfo%20%28most%20Linux%20and%20Unix%20based%20systems%29%0D%0AThis%20plugi&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=40&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.shareaholic.com/api/share/?title=Nagios+Memeory+Check+Plugin+-+download+%26+install&amp;link=http://www.the-tech-tutorial.com/?p=1435&amp;notes=When%20I%20noticed%20that%20Nagios%20had%20no%20memory%20check%20plugin%20I%20decided%20to%20make%20a%20simple%20bash%20plugin%20for%20Nagios%20to%20check%20how%20much%20memory%20my%20machines%20were%20using.%20It%20works%20by%20reading%20%2Fproc%2Fmeminfo%20so%20it%20should%20work%20on%20every%20system%20were%20you%20can%20read%20%2Fproc%2Fmeminfo%20%28most%20Linux%20and%20Unix%20based%20systems%29%0D%0AThis%20plugi&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=38&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://www.shareaholic.com/api/share/?title=Nagios+Memeory+Check+Plugin+-+download+%26+install&amp;link=http://www.the-tech-tutorial.com/?p=1435&amp;notes=When%20I%20noticed%20that%20Nagios%20had%20no%20memory%20check%20plugin%20I%20decided%20to%20make%20a%20simple%20bash%20plugin%20for%20Nagios%20to%20check%20how%20much%20memory%20my%20machines%20were%20using.%20It%20works%20by%20reading%20%2Fproc%2Fmeminfo%20so%20it%20should%20work%20on%20every%20system%20were%20you%20can%20read%20%2Fproc%2Fmeminfo%20%28most%20Linux%20and%20Unix%20based%20systems%29%0D%0AThis%20plugi&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=%2524%257Btitle%257D%2B-%2B%2524%257Bshort_link%257D&amp;service=7&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.shareaholic.com/api/share/?title=Nagios+Memeory+Check+Plugin+-+download+%26+install&amp;link=http://www.the-tech-tutorial.com/?p=1435&amp;notes=When%20I%20noticed%20that%20Nagios%20had%20no%20memory%20check%20plugin%20I%20decided%20to%20make%20a%20simple%20bash%20plugin%20for%20Nagios%20to%20check%20how%20much%20memory%20my%20machines%20were%20using.%20It%20works%20by%20reading%20%2Fproc%2Fmeminfo%20so%20it%20should%20work%20on%20every%20system%20were%20you%20can%20read%20%2Fproc%2Fmeminfo%20%28most%20Linux%20and%20Unix%20based%20systems%29%0D%0AThis%20plugi&amp;short_link=&amp;shortener=google&amp;shortener_key=&amp;v=1&amp;apitype=1&amp;apikey=8afa39428933be41f8afdb8ea21a495c&amp;source=Shareaholic&amp;template=&amp;service=88&amp;tags=&amp;ctype=" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
</ul><div style="clear: both;"></div><div class="shr-getshr" style="visibility:hidden;font-size:10px !important"><a target="_blank" href="https://shareaholic.com/?src=pub">Get Shareaholic</a></div><div style="clear: both;"></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.the-tech-tutorial.com/?feed=rss2&#038;p=1435</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
