<?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>opensourcetutor.com &#187; Bash</title>
	<atom:link href="http://www.opensourcetutor.com/category/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.opensourcetutor.com</link>
	<description>On Linux, Web Development, Joomla and Magento commerce</description>
	<lastBuildDate>Sat, 04 Feb 2012 10:27:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Yakuake for Gnome</title>
		<link>http://www.opensourcetutor.com/2009/08/03/yakuake-for-gnome/</link>
		<comments>http://www.opensourcetutor.com/2009/08/03/yakuake-for-gnome/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 00:53:29 +0000</pubDate>
		<dc:creator>salubrium</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux Administration]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[desktop shortcuts]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tilda]]></category>
		<category><![CDATA[yakuake]]></category>

		<guid isPermaLink="false">http://www.opensourcetutor.com/?p=240</guid>
		<description><![CDATA[



I have previously written about Tilda, a gnome replacement for Yakuake. I had some issues with Tilda so I came to have a nice relationship with Yakauke. It&#8217;s important to note though, that there is another reasonable alternative to both Tilda and Yakuake and it&#8217;s called Guake.
Guake has some of the basic features of Yakuake but is still lacking in a few things. The main ones for me are:

Yakauke allows you to choose terminal width / Guake takes up fullscreen width. The advantage of this for me is that I ...]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-9469051832075629";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
//2007-05-22: opensourcetutor.com
google_ad_channel = "3549963802";
google_color_border = "FFF";
google_color_bg = "FFF";
google_color_link = "333";
google_color_text = "CCCCCC";
google_color_url = "999999";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
I have <a href="http://www.opensourcetutor.com/2007/06/11/tilda-the-yakuake-terminal-equivalent-for-gnome/">previously written about Tilda</a>, a gnome replacement for <a href="http://yakuake.kde.org/">Yakuake</a>. I had some issues with Tilda so I came to have a nice relationship with Yakauke. It&#8217;s important to note though, that there is another reasonable alternative to both Tilda and Yakuake and it&#8217;s called <a href="http://trac.guake-terminal.org/">Guake</a>.</p>
<p>Guake has some of the basic features of Yakuake but is still lacking in a few things. The main ones for me are:</p>
<ul>
<li>Yakauke allows you to choose terminal width / Guake takes up fullscreen width. The advantage of this for me is that I can sit Yakuake on the right side of the page and read a web page as a reference if I am programming in vim or copying instructions for something.</li>
<li>Yakuake allows you to Alt+Shift+Left/Right to increase / decrease terminal width size on the fly. So if you can&#8217;t quite read the text you are referencing, it&#8217;s easy to shrink the terminal slightly so you can.</li>
</ul>
<p>Still, if you are looking for a nice Gnome-based Quake style terminal window, Guake is a good alternative to both Tilda and Yakuake.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcetutor.com/2009/08/03/yakuake-for-gnome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to compress css &amp; javascript: An alternative to mod_deflate or mod_gzip</title>
		<link>http://www.opensourcetutor.com/2009/06/01/how-to-compress-css-javascript-an-alternative-to-mod_deflate-or-mod_gzip/</link>
		<comments>http://www.opensourcetutor.com/2009/06/01/how-to-compress-css-javascript-an-alternative-to-mod_deflate-or-mod_gzip/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 07:35:27 +0000</pubDate>
		<dc:creator>salubrium</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Linux Administration]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[mod_deflate]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[yslow]]></category>

		<guid isPermaLink="false">http://www.opensourcetutor.com/2009/06/01/how-to-compress-css-javascript-an-alternative-to-mod_deflate-or-mod_gzip/</guid>
		<description><![CDATA[



So, you have used Website Optimization Analyzer or you installed Yslow for Firefox or you discovered somewhere else that compressing your files (html, javascript &#38; css) is a good thing to do. Unfortunately, it&#8217;s not always as easy as it looks to do this.
In Apache web hosting environments, there is a module called mod_deflate (for 2.x versions) or mod_gzip (for 1.3) versions. This is generally the easiest way to get content compressed. As in my last post about Magento, you should normally be able to enable this safely with the ...]]></description>
			<content:encoded><![CDATA[<p><!--adsense#widelinks--></p>
<p>So, you have used <a href="http://www.websiteoptimization.com/services/analyze/" target="_blank">Website Optimization Analyzer</a> or you installed <a href="https://addons.mozilla.org/en-US/firefox/addon/5369" target="_blank">Yslow for Firefox</a> or you discovered somewhere else that compressing your files (html, javascript &amp; css) is a good thing to do. Unfortunately, it&#8217;s not always as easy as it looks to do this.</p>
<p>In Apache web hosting environments, there is a module called mod_deflate (for 2.x versions) or mod_gzip (for 1.3) versions. This is generally the easiest way to get content compressed. As in my <a href="http://www.opensourcetutor.com/2009/04/07/how-to-speed-up-magento-ecommerce/" target="_blank">last post about Magento</a>, you should normally be able to enable this safely with the following lines inside your .htaccess file in your www root of your website:</p>
<p><code>&lt;ifmodule mod_deflate.c&gt;<br />
    # Insert filter<br />
    SetOutputFilter DEFLATE<br />
    # Netscape 4.x has some problems...<br />
    BrowserMatch ^Mozilla/4 gzip-only-text/html<br />
    # Netscape 4.06-4.08 have some more problems<br />
    BrowserMatch ^Mozilla/4\.0[678] no-gzip<br />
    # MSIE masquerades as Netscape, but it is fine<br />
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html<br />
    # Don't compress images<br />
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary<br />
    # Make sure proxies don't deliver the wrong content<br />
    Header append Vary User-Agent env=!dont-vary<br />
&lt;/ifmodule&gt;</code></p>
<p>Then visit your website and in your browser right-click on the web page and choose &#8220;View Source&#8221;. In the source code, try and find a line that contains your stylesheet, then we go to <a href="http://www.whatsmyip.org/http_compression/" target="_blank">whatsmyip compression checker</a> and we enter the whole URL to your stylesheet there. To test, enter my css url.</p>
<p><code>http://www.opensourcetutor.com/wp-content/themes/hemingwayEx/style.css</code></p>
<p>You should see a big green tick and the site will say the CSS is compressed. Now, if you don&#8217;t, you either haven&#8217;t applied my above .htaccess settings yet or mod_deflate is not enabled on your server for you to access.</p>
<h2>Alternative #1 &#8211; requires Apache mod_rewrite</h2>
<p>This method is probably the best method I have seen to overcome the mod_deflate issue and we are only concerned about javascript and css files for now. PHP has an easy method to compress php files on the fly. What we need to do is gzip all our javascript &amp; css files.</p>
<p>If you have shell access, you can run this command to take of the job for you. It will find each and every javascript file and css file and create a gzip copy.</p>
<p><code>find . -regex ".*\(css\|js\)$" -exec bash -c 'echo Compressing "{}" &amp;amp;&amp;amp; gzip -c --best "{}" &gt; "{}.gz"' \;</code></p>
<p>The line above searches the current directory and any subdirectories for files with extensions .js or .css, then prints out that it is being compressed, then compresses with the highest compression in that directory leaving the original file as is.</p>
<p>Now, we need to tell our browser to access the gzip version *IF* it supports gzip encoding. To do this, we use the following in our .htaccess file. Make sure you have removed the above code if it wasn&#8217;t successful.</p>
<pre>
<code>&lt;files *.js.gz&gt;
  AddType "text/javascript" .gz
  AddEncoding gzip .gz
&lt;/files&gt;
&lt;files *.css.gz&gt;
  AddType "text/css" .gz
  AddEncoding gzip .gz
&lt;/files&gt;
RewriteEngine on
#Check to see if browser can accept gzip files.
ReWriteCond %{HTTP:accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Safari
#make sure there's no trailing .gz on the url
ReWriteCond %{REQUEST_FILENAME} !^.+\.gz$
#check to see if a .gz version of the file exists.
RewriteCond %{REQUEST_FILENAME}.gz -f
#All conditions met so add .gz to URL filename (invisibly)
RewriteRule ^(.+) $1.gz [QSA,L] </code>
</pre>
<p>The advantage of this Alternative is that our server doesn&#8217;t have to gzip / compress the javascript and css each time it is called. This eases the load up on the server as we already do the compression one time and then just call the compressed version from then after. The other advantage is that we don&#8217;t need to load up mod_deflate each time. This could be advantages if you are running a VPS with very low memory available.</p>
<p>If you have a static website, you could apply the same technique for all your html files. To do so, you would instead use this line:</p>
<p><code>find . -regex ".*\(html\|css\|js\)$" -exec bash -c 'echo Compressing "{}" &amp;amp;&amp;amp; gzip -c --best "{}" &gt; "{}.gz"' \;</code></p>
<p>and then add this into your .htaccess also</p>
<pre>
<code>&lt;files *.html.gz&gt;
  AddType "text/html" .gz
  AddEncoding gzip .gz
&lt;/files&gt;</code>
</pre>
<p><!--adsense#widelinks--></p>
<p>
Technorati Tags: <a class="performancingtags" href="http://technorati.com/tag/apache" rel="tag">apache</a>, <a class="performancingtags" href="http://technorati.com/tag/gzip" rel="tag">gzip</a>, <a class="performancingtags" href="http://technorati.com/tag/mod_deflate" rel="tag">mod_deflate</a>, <a class="performancingtags" href="http://technorati.com/tag/compression" rel="tag">compression</a>, <a class="performancingtags" href="http://technorati.com/tag/yslow" rel="tag">yslow</a>, <a class="performancingtags" href="http://technorati.com/tag/firefox" rel="tag">firefox</a>, <a class="performancingtags" href="http://technorati.com/tag/optimization" rel="tag">optimization</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcetutor.com/2009/06/01/how-to-compress-css-javascript-an-alternative-to-mod_deflate-or-mod_gzip/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Boo Language aspx .Net using xsp2 on Mono and Linux (Ubuntu)</title>
		<link>http://www.opensourcetutor.com/2008/10/29/boo-language-aspx-net-using-xsp2-on-mono-and-linux-ubuntu/</link>
		<comments>http://www.opensourcetutor.com/2008/10/29/boo-language-aspx-net-using-xsp2-on-mono-and-linux-ubuntu/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 10:47:26 +0000</pubDate>
		<dc:creator>salubrium</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Internet Goodness]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[boo]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mono]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[xsp]]></category>

		<guid isPermaLink="false">http://www.opensourcetutor.com/2008/10/29/boo-language-aspx-net-using-xsp2-on-mono-and-linux-ubunut/</guid>
		<description><![CDATA[I have been playing around with boo a little bit because it has Python-inspired syntax, runs at C# speeds and is a first class citizen on dotnet.
So I decided to find out what it would be like to do some web programming in it. I learned a bit about asp.Net in the process and mono also.
So first thing I did was:
$ cd /usr/share/doc/boo/examples/asp.net$ xsp2
and then from your browser you can run any of the &#8220;inline&#8221; samples
http://localhost:8080/InlineBooButtonClick.aspxhttp://localhost:8080/InlineBooExpression.aspxhttp://localhost:8080/InlineBooHelloAspNet.aspx
but if you try and run one of the code behind samples, you get something ...]]></description>
			<content:encoded><![CDATA[<p>I have been playing around with boo a little bit because it has Python-inspired syntax, runs at C# speeds and is a first class citizen on dotnet.</p>
<p>So I decided to find out what it would be like to do some web programming in it. I learned a bit about asp.Net in the process and mono also.</p>
<p>So first thing I did was:</p>
<blockquote><p>$ cd /usr/share/doc/boo/examples/asp.net<br />$ xsp2</p></blockquote>
<p>and then from your browser you can run any of the &#8220;inline&#8221; samples</p>
<p>http://localhost:8080/InlineBooButtonClick.aspx<br />http://localhost:8080/InlineBooExpression.aspx<br />http://localhost:8080/InlineBooHelloAspNet.aspx</p>
<p>but if you try and run one of the code behind samples, you get something like this:</p>
<p><img style="max-width: 800px;" src="http://www.opensourcetutor.com/wp-content/uploads/2008/10/parser-error-1225276749810.png" /></p>
<blockquote><p>Description: Error parsing a resource required to service this request. Review your source file and modify it to fix this error.</p>
<p>Parser Error Message: Cannot find type Boo.Examples.Web.YourName</p>
<p>Source Error:</p>
<p>Line 1: &lt;%@Page Inherits=&#8221;Boo.Examples.Web.YourName&#8221;  %&gt;<br />Line 2: <br />Line 3: </p></blockquote>
<p>The problem is the the boo source code needs to be compiled and the dll&#8217;s must be placed in a bin directory in the folder you are running xsp2 from. There is a nant build script there but after trying to hack it to get it to build, we worked out it was easier to just compile manually.ie:</p>
<blockquote><p>$ sudo mkdir bin<br />$ sudo booc -t:library -o:ScriptRunner.dll ScriptRunner.aspx.boo<br />$ sudo cp ScriptRunner.dll bin</p></blockquote>
<p>from your browser:</p>
<p>http://localhost:8080/ScriptRunner.aspx</p>
<p>You can then use this to play around with some boo as if it were the booshell (booish)</p>
<p>Thanks to Cedric for helping me out in IRC on this.Technorati Tags: <a class="performancingtags" href="http://technorati.com/tag/mono" rel="tag">mono</a>, <a class="performancingtags" href="http://technorati.com/tag/python" rel="tag">python</a>, <a class="performancingtags" href="http://technorati.com/tag/boo" rel="tag">boo</a>, <a class="performancingtags" href="http://technorati.com/tag/language" rel="tag">language</a>, <a class="performancingtags" href="http://technorati.com/tag/xsp" rel="tag">xsp</a>, <a class="performancingtags" href="http://technorati.com/tag/ubuntu" rel="tag">ubuntu</a>, <a class="performancingtags" href="http://technorati.com/tag/linux" rel="tag">linux</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcetutor.com/2008/10/29/boo-language-aspx-net-using-xsp2-on-mono-and-linux-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bulk Export Images to JPG from PDF &#8211; bash one liner</title>
		<link>http://www.opensourcetutor.com/2008/10/19/bulk-export-images-to-jpg-from-pdf-bash-one-liner/</link>
		<comments>http://www.opensourcetutor.com/2008/10/19/bulk-export-images-to-jpg-from-pdf-bash-one-liner/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 06:43:42 +0000</pubDate>
		<dc:creator>salubrium</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux Administration]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.opensourcetutor.com/2008/10/19/bulk-export-images-to-jpg-from-pdf-bash-one-liner/</guid>
		<description><![CDATA[Sometimes I forget what power there is in free software. I put this quickie together the other day. Just be aware that it won&#8217;t handle any spaces in the PDF filename.
for i in *.pdf;do pdfimages $i ${i%.*};done &#38;&#38; for i in *.ppm;do ppmtojpeg $i &#62;&#62; ${i%.*}.jpg;done; rm -f *.ppm
images are exported as
-00n.jpg &#8211; ie: the n&#8217;th image found in the pdf.
]]></description>
			<content:encoded><![CDATA[<p>Sometimes I forget what power there is in free software. I put this quickie together the other day. Just be aware that it won&#8217;t handle any spaces in the PDF filename.</p>
<blockquote><p>for i in *.pdf;do pdfimages $i ${i%.*};done &amp;&amp; for i in *.ppm;do ppmtojpeg $i &gt;&gt; ${i%.*}.jpg;done; rm -f *.ppm</p></blockquote>
<p>images are exported as
<pdfname>-00n.jpg &#8211; ie: the n&#8217;th image found in the pdf.</pdfname>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcetutor.com/2008/10/19/bulk-export-images-to-jpg-from-pdf-bash-one-liner/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to schedule Linux to mute speaker volume overnight</title>
		<link>http://www.opensourcetutor.com/2008/04/28/how-to-schedule-linux-to-mute-speaker-volume-overnight/</link>
		<comments>http://www.opensourcetutor.com/2008/04/28/how-to-schedule-linux-to-mute-speaker-volume-overnight/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 06:35:46 +0000</pubDate>
		<dc:creator>salubrium</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux Administration]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[crontab]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[volume]]></category>

		<guid isPermaLink="false">http://www.opensourcetutor.com/2008/04/28/how-to-schedule-linux-to-mute-speaker-volume-overnight/</guid>
		<description><![CDATA[
Here&#8217;s a simple method of automatically muting your volume overnight and resetting it in the morning. This is especially good for those who use softphones, skype or an IM client that have sound alerts output to speakers.
We are going to use three command line tools for this: aumix, which and cron. We are also only going to set things up so the commands are run under the user account, rather than as root as cron used incorrectly can open up some security issues.
so, to get started try and run:
:~$ aumix
and ...]]></description>
			<content:encoded><![CDATA[<p><!--adsense#widelinks--><br />
Here&#8217;s a simple method of automatically muting your volume overnight and resetting it in the morning. This is especially good for those who use softphones, skype or an IM client that have sound alerts output to speakers.</p>
<p>We are going to use three command line tools for this: aumix, which and cron. We are also only going to set things up so the commands are run under the user account, rather than as root as cron used incorrectly can open up some security issues.</p>
<p>so, to get started try and run:</p>
<blockquote><p>:~$ aumix</p></blockquote>
<p>and if it&#8217;s not there, try</p>
<blockquote><p>:~$ sudo apt-get install aumix</p></blockquote>
<p> for Debian / Ubuntu or <br />
<blockquote>:~$ yum install aumix</p></blockquote>
<p> for Redhat / Centos / Fedora</p>
<p>Now that we have aumix installed, we want to find out the path to the executable as Cron doesn&#8217;t always use our environmental variables to find executables on our path. So type:</p>
<blockquote><p>:~$ which aumix<br />/usr/bin/aumix </p></blockquote>
<p>We can see it&#8217;s in /usr/bin/aumix</p>
<p>So, kick-off your music player and try playing some music or other audio then run the following commands:</p>
<blockquote><p>:~$ aumix -v 0</p></blockquote>
<p>  then<br />
<blockquote>:~$ aumix -v 100</p></blockquote>
<p>The first command should have dropped your volume down to 0% and the second command should have taken it back to 100%. Now that we have that working, let&#8217;s add it to cron. For myself, I don&#8217;t want to be disturbed between 11pm and 7am, so following cron&#8217;s options, we have</p>
<p>minute-hour-day-month-weekday-command &#8211; and we use 24 hour format. An asterisk means run at every instance of that time period, so:<br /> * * * * * would mean every minute of every day, every month and<br /> 0 0 * * * would mean at midnight every day.</p>
<p>For myself, I want the 23rd hour of every day, every month for the volume to be set down and I want the 7th hour of every day for the volume to be returned to 90%. So we add this to our crontab:</p>
<blockquote><p>0 23 * * * /usr/bin/aumix -v 0<br />00 07 * * * /usr/bin/aumix -v 90</p></blockquote>
<p>To do so as a user, we use:</p>
<blockquote><p>:~$ crontab -e</p></blockquote>
<p>Now if your default editor is vim / vi and you have never used it before, you will need to learn a little vi before we get started. When the editor opens, type <i> to enter insert mode allowing you to copy and paste the above code and modify for your needs, when you are finished editing, press esc then VV to save the file and exit.</p>
<p>If the above vi / vim is too difficult, then you can make nano your default editor (if it&#8217;s not already)</p>
<p></i><br />
<blockquote><i>:~$ EDITOR=/usr/bin/nano</i></p></blockquote>
<p><i> and then run <br /></i><br />
<blockquote><i>:~$ crontab -e</i></p></blockquote>
<p><i></p>
<p>Nano is a simplistic editor with the basic instructions displayed at the bottom of the screen.</p>
<p>So, there you have the very basics of Cron administration &#8211; ie: the Task Scheduler of Linux and how to adjust your volume via the command line.</p>
<p>If you are looking for a GUI tool for Cron Administration, look no further than gnome-schedule:</p>
<p></i><br />
<blockquote><i>:~$ sudo apt-get install gnome-schedule</i></p></blockquote>
<p><i></p>
<p>here&#8217;s our beloved screenshot:</p>
<p></i>
<div align="center"><img style="max-width: 800px;" src="http://www.opensourcetutor.com/wp-content/uploads/2008/04/gnome-schedule.png" /></div>
<p>for raising and lowering the volume.</p>
<p>Technorati Tags: <a class="performancingtags" href="http://technorati.com/tag/volume" rel="tag">volume</a>, <a class="performancingtags" href="http://technorati.com/tag/linux" rel="tag">linux</a>, <a class="performancingtags" href="http://technorati.com/tag/crontab" rel="tag">crontab</a>, <a class="performancingtags" href="http://technorati.com/tag/automation" rel="tag">automation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcetutor.com/2008/04/28/how-to-schedule-linux-to-mute-speaker-volume-overnight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Troubleshooting Apache with mod_status, strace, apachetop, iftop &amp; top</title>
		<link>http://www.opensourcetutor.com/2007/08/04/troubleshooting-apache-with-mod_status-strace-apachetop-iftop-top/</link>
		<comments>http://www.opensourcetutor.com/2007/08/04/troubleshooting-apache-with-mod_status-strace-apachetop-iftop-top/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 13:42:01 +0000</pubDate>
		<dc:creator>salubrium</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Linux Administration]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.opensourcetutor.com/2007/08/04/troubleshooting-apache-with-mod_status-strace-apachetop-iftop-top/</guid>
		<description><![CDATA[Ok &#8211; some real-life critical experience today.. one of our web servers notifies us (thanks to csf / lfd firewall ) that the server has had a high load for greater than 5 minutes. I get logged in and see the 5,10 &#38; 15 minute load average exceeding  30 and this server normally runs at a load of &#60;1
Here&#8217;s the MRTG Graph of the load:

A quick look at top showed me approx 15 httpd (apache) processes maxxing out the CPU. Now, it&#8217;s a shared server with hundreds of Virtual ...]]></description>
			<content:encoded><![CDATA[<p><!--adsense#widelinks-->Ok &#8211; some real-life critical experience today.. one of our web servers notifies us (thanks to <a href="http://www.configserver.com/cp/csf.html">csf / lfd firewall</a> ) that the server has had a high load for greater than 5 minutes. I get logged in and see the 5,10 &amp; 15 minute load average exceeding  30 and this server normally runs at a load of &lt;1</p>
<p>Here&#8217;s the MRTG Graph of the load:</p>
<div align="center"><img src="http://www.opensourcetutor.com/wp-content/uploads/2007/08/load-day.png" /></div>
<p>A quick look at top showed me approx 15 httpd (apache) processes maxxing out the CPU. Now, it&#8217;s a shared server with hundreds of Virtual hosts and we need to find out which site is causing the issue.</p>
<p>Now, here&#8217;s the fun part &#8211; mod_status can help us out here, if we have it enabled.</p>
<p>/etc/init.d/httpd fullstatus or /etc/httpd/bin/apachectl fullstatus</p>
<p>should give you some output like</p>
<blockquote><p>Srv	PID	Acc	M	CPU	SS	Req	Conn	Child	Slot	Host	VHost	Request<br />0-0	4419	0/403/403	_ 	70.45	5	9	0.0	2.20	2.20 	220.181.19.162	www.domain.com	GET /096.htm HTTP/1.1 <br />1-0	4420	0/270/270	_ 	7.97	4	20	0.0	1.33	1.33 	66.249.72.228	www.domain.com.au	GET May24.htm HTTP/1.1 <br />2-0	4421	2/274/274	K 	8.49	2	319	0.0	1.03	1.03 	66.249.72.228	www.cdomain.com.au	GET /refrigeration/<br />3-0	4422	1/334/334	K 	13.37	1	43	0.0	1.70	1.70 	66.249.72.228	www.domain.com.au	GET /image.php?number=11 HTTP/1.1 <br />4-0	4423	0/211/211	_ 	28.61	15	277	0.0	0.71	0.71 	203.94.138.108	www.domain.com	POST /mbalert.php HTTP/1.1</p></blockquote>
<p>This obviously, isn&#8217;t the data from the moment the issue appeared but it was clearly obvious that it was one site causing the issue. I was a bit surprised because the majority of our servers run an Apache module called <a href="http://www.zdziarski.com/projects/mod_evasive/">mod_evasive</a> which in their own words does:</p>
<blockquote><p>mod_evasive is an evasive maneuvers module for Apache to provide evasive action in the event of an HTTP DoS or DDoS attack or brute force attack. It is also designed to be a detection and network management tool, and can be easily configured to talk to ipchains, firewalls, routers, and etcetera. mod_evasive presently reports abuses via email and syslog facilities. </p>
<p>Detection is performed by creating an internal dynamic hash table of IP Addresses and URIs, and denying any single IP address from any of the following: <br />Requesting the same page more than a few times per second <br />Making more than 50 concurrent requests on the same child per second <br />Making any requests while temporarily blacklisted (on a blocking list)</p></blockquote>
<p>Anyway, after a recent upgrade the server didn&#8217;t have mod_evasive installed. We know which site is causing the issue but the customer who owns the site is one of our best customers and it&#8217;s a Joomla site that we helped develop, so it&#8217;s important to keep it up and fix the issue.</p>
<p>Now, I need to know WHY the site is chewing so much CPU. </p>
<p>Tool #1. <a href="http://www.ex-parrot.com/%7Epdw/iftop/">iftop</a>  &#8211; is like top for interface traffic. It shows local ip and port, remote ip and port and a graphic representation of the immediate traffic for the connection as well as totals and averages.</p>
<p>- are we seeing huge amounts of excessive traffic to the server, as in a DDOS attack? No let&#8217;s move on to the next tool.</p>
<p>Tool #2. <a href="http://spork.qfe3.net/apachetop/">apachetop</a> &#8211; Apache top is like &#8216;top&#8217; but for apache. The problem with it is that it needs to look at your server log and in this case, the Virtual Server has it&#8217;s own log, so we had to know which Website it was before using apachetop.</p>
<p>It&#8217;s most basic syntax is: apachetop -f /path/to/virtual_server.log</p>
<p>Ok, now we are able to see that the issue is from a web crawler called &#8220;webwombat&#8221; &#8211; An Australian search engine (that I have never heard of)</p>
<p>So, we grab the IP addresses of their bots and add them to the deny file for the firewall.. this is temporary to stop the load while we fix the underlying problem.</p>
<p>Tool #3. <a href="http://sourceforge.net/projects/strace/">strace</a> -What is strace?</p>
<p>strace is a system call tracer, i.e. a debugging tool which prints out a trace of all the system calls made by a another process/program.</p>
<p>strace is a hard tool to use with anything that spawns child processes. Because it only attaches itself to the process you tell it to and who knows which process is going to serve the next request? I guess you could change your httpd.conf to only run a single child process but for myself, I setup a small script with an infinite loop using wget or curl that calls a page of the site I am trying to catch. I then attach strace to one of the apache processes I see in top:</p>
<p>strace -p &lt;processid&gt;
<pid>
<p>and with my script running, within a minute or two I will see my chosen pid serve the request to the client (the script) and as it completes, I kill Ctrl-C out of strace (ensure you have a long buffer in your terminal window)</p>
<p>As the site in question is served, I noticed a very strange pattern that I didn&#8217;t see with other sites being served and here is a section of the output from strace:</p>
</pid>
<blockquote>setsockopt(12, SOL_SOCKET, SO_RCVTIMEO, &#8220;\2003\341\1\0\0\0\0&#8243;, 8) = 0<br />read(12, &#8220;\213\0\0\25&#8243;, 4)              = 4<br />read(12, &#8220;\003568\2-1\n/uniforms/:index.php?opt&#8221;&#8230;, 139) = 139<br />setsockopt(12, SOL_SOCKET, SO_RCVTIMEO, &#8220;\2003\341\1\0\0\0\0&#8243;, 8) = 0<br />read(12, &#8220;\253\0\0\26&#8243;, 4)              = 4<br />read(12, &#8220;\003555\2-1)/refrigeration/glass-doo&#8221;&#8230;, 171) = 171<br />setsockopt(12, SOL_SOCKET, SO_RCVTIMEO, &#8220;\2003\341\1\0\0\0\0&#8243;, 8) = 0<br />read(12, &#8220;\237\0\0\27&#8243;, 4)              = 4<br />read(12, &#8220;\003554\2-1\35/refrigeration/chest-fre&#8221;&#8230;, 159) = 159<br />setsockopt(12, SOL_SOCKET, SO_RCVTIMEO, &#8220;\2003\341\1\0\0\0\0&#8243;, 8) = 0<br />read(12, &#8220;\237\0\0\30&#8243;, 4)              = 4<br />read(12, &#8220;\003553\2-1\36/food-preparation/meat-s&#8221;&#8230;, 159) = 159<br />setsockopt(12, SOL_SOCKET, SO_RCVTIMEO, &#8220;\2003\341\1\0\0\0\0&#8243;, 8) = 0<br />read(12, &#8220;\271\0\0\31&#8243;, 4)              = 4<br />read(12, &#8220;\003552\2-1:/food-display/hot-food-d&#8221;&#8230;, 185) = 185<br />setsockopt(12, SOL_SOCKET, SO_RCVTIMEO, &#8220;\2003\341\1\0\0\0\0&#8243;, 8) = 0<br />read(12, &#8220;\242\0\0\32&#8243;, 4)              = 4<br />read(12, &#8220;\003551\2-1 /food-preparation/spiral&#8221;&#8230;, 162) = 162<br />setsockopt(12, SOL_SOCKET, SO_RCVTIMEO, &#8220;\2003\341\1\0\0\0\0&#8243;, 8) = 0<br />read(12, &#8220;\242\0\0\33&#8243;, 4)              = 4<br />read(12, &#8220;\003550\2-1\37/uniforms/hospitality-cl&#8221;&#8230;, 162) = 162<br />setsockopt(12, SOL_SOCKET, SO_RCVTIMEO, &#8220;\2003\341\1\0\0\0\0&#8243;, 8) = 0<br />read(12, &#8220;\240\0\0\34&#8243;, 4)              = 4<br />read(12, &#8220;\003549\2-1\36/used-equipment/cash-reg&#8221;&#8230;, 160) = 160<br />setsockopt(12, SOL_SOCKET, SO_RCVTIMEO, &#8220;\2003\341\1\0\0\0\0&#8243;, 8) = 0<br />read(12, &#8220;\242\0\0\35&#8243;, 4)              = 4<br />read(12, &#8220;\003548\2-1 /miscellaneous/bag-seale&#8221;&#8230;, 162) = 162<br />setsockopt(12, SOL_SOCKET, SO_RCVTIMEO, &#8220;\2003\341\1\0\0\0\0&#8243;, 8) = 0<br />read(12, &#8220;\247\0\0\36&#8243;, 4)              = 4</p></blockquote>
<p>it was rows and rows of that. I go and take a look at the site. It has &gt;700 items in a catalogue style layout. There were two issues:</p>
<p>Problem 1. The site is using SWMenu Pro &#8211; the client had requested that all 700 items in the catalogue be accessible from the flyout javascript menu and so, of course the client wasn&#8217;t talked out of his madness instead the developers complied &#8211; it currently pumps out &gt;150kb of HTML for each page that loads. PHP was creating it for each page load. Fortunately has a caching option *that wasn&#8217;t turned on* &#8211; so you know what I did? Now the menu is cached, it no longer has to recreate it each time. That was half our problem fixed. Page load times dropped from approx 8 seconds, down to about 4-5 seconds.</p>
<p>Problem 2. OPEN SEF &#8211; I actually love Open SEF because it prevents you being a prime target to fresh Joomla security exploits by hackers using google. The problem in this case is that it is converting over 700 url&#8217;s on each page load. CPU killer number 2. This is a harder issue to fix but SWMenu has some good functionality that is just too hard to explain in writing.. but put simply, it allows you to manage an infinite amount of menu levels in a very granular way.  I don&#8217;t feel I need to get into this just now but at least it&#8217;s there if we have further issues.</p>
<p>I watched Googlebot go over the site and load stayed very low and it&#8217;s certainly not the kind of site that will get on Digg, Reddit or Slashdot, so I am satisfied with that for now.</p>
<p>The only thing that needs to be done, is to install mod_evasive, this would prevent bots like webwombat from being able to make too many simultaneous requests. If you DO run mod_evasive be aware that you want to be careful with it. Some things to watch out for:</p>
<ul>
<li>Make sure mod_evasive isn&#8217;t blocking google. Your customers wouldn&#8217;t be happy for the traffic they are losing.</li>
<li>If you do any load testing, make sure you disable mod_evasive before doing so</li>
</ul>
<p>Good luck.. and kudos to all those who wrote the great tools above.</p>
<p>Technorati Tags: <a class="performancingtags" href="http://technorati.com/tag/apache" rel="tag">apache</a>, <a class="performancingtags" href="http://technorati.com/tag/mod_status" rel="tag">mod_status</a>, <a class="performancingtags" href="http://technorati.com/tag/mod_evasive" rel="tag">mod_evasive</a>, <a class="performancingtags" href="http://technorati.com/tag/apachetop" rel="tag">apachetop</a>, <a class="performancingtags" href="http://technorati.com/tag/strace" rel="tag">strace</a>, <a class="performancingtags" href="http://technorati.com/tag/iftop" rel="tag">iftop</a>, <a class="performancingtags" href="http://technorati.com/tag/troubleshooting" rel="tag">troubleshooting</a>, <a class="performancingtags" href="http://technorati.com/tag/joomla" rel="tag">joomla</a></p>
<p class="poweredbyperformancing">Powered by <a href="http://scribefire.com/">ScribeFire</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcetutor.com/2007/08/04/troubleshooting-apache-with-mod_status-strace-apachetop-iftop-top/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

