<?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>Saiweb</title>
	<atom:link href="http://www.saiweb.co.uk/feed" rel="self" type="application/rss+xml" />
	<link>http://www.saiweb.co.uk</link>
	<description>Ramblings of a Sys admin</description>
	<lastBuildDate>Thu, 26 Aug 2010 18:13:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP &amp; Caching an in depth review.</title>
		<link>http://www.saiweb.co.uk/hosting/php-caching-an-in-depth-review</link>
		<comments>http://www.saiweb.co.uk/hosting/php-caching-an-in-depth-review#comments</comments>
		<pubDate>Thu, 26 Aug 2010 18:11:59 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[faster]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=800</guid>
		<description><![CDATA[Sounds simple enough, right? Use a cache to serve pages faster, well yes that is true but people often do not realize the fundamentals of caching and how if not done properly it can lead to a detriment in performance. The first thing you need to realize that by caching your content is no longer [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.saiweb.co.uk%2Fhosting%2Fphp-caching-an-in-depth-review"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.saiweb.co.uk%2Fhosting%2Fphp-caching-an-in-depth-review&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Sounds simple enough, right?</p>
<p>Use a cache to serve pages faster, well yes that is true but people often do not realize the fundamentals of caching and how if not done properly it can lead to a detriment in performance.</p>
<p>The first thing you need to realize that by caching your content is no longer dynamic, &#8230; (short pause while we wait for the outrage in the back to die down).</p>
<p>The whole point behind your cache is that it will be used instead of processing all your code, why this is beneficial?</p>
<p>You have to remember that PHP is an interpreted language, meaning it takes the following I/O flow:</p>
<p>Apache -&gt; mod_php -&gt; Script -&gt; Interpreter -&gt; Bytecode -&gt; Execution -&gt; Output Buffer</p>
<p>Now there are two types of caching to consider, the first is completion output caching, this also yields the best performance, the second is opcode caching, this caches the byte code generated by the interpreter thus removing that step from the chain of execution.</p>
<p>With me so far? Ok take a deep breath because here we go &#8230;</p>
<p><strong>Output caching</strong></p>
<p>This option often yields the best performance, but at the cost of removing the dynamic element from your web app.<br />
But this can be summed up in a single line: What good is dynamic content if you can serve all of 5% of your audience at a given time?</p>
<p>Another turn of phrase is &#8220;The slashdot effect&#8221;, there are many options for output caching, and you should ideally provide gziped and plain cache files to your end user,  for instance on this blog I use WP Super Cache, and can high recommend it, as new content is posted the relevant caches are regenerated, if you are writing your own WebApp check for the &#8220;Accept-Encoding:gzip&#8221; header being sent via the users browser.</p>
<p>For end user transparency couple this with some mod_rewrite voodoo</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RewriteCond %{HTTP:Accept-Encoding} gzip<br />
RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}/%{REQUEST_FILENAME}.gz -f<br />
RewriteRule ^(.*) &quot;/cache/%{HTTP_HOST}/%{REQUEST_FILENAME}.gz&quot; [L]</div></td></tr></tbody></table></div>
<p>1: If gzip is supported<br />
2: and the cache file exists<br />
3: Redirect visitor to compressed cached file</p>
<p>You &#8220;chain of execution&#8221; is now</p>
<p>Apache -&gt; readfile</p>
<p>To serve non gziped content:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RewriteCond %{HTTP:Accept-Encoding} !gzip<br />
RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}/%{REQUEST_FILENAME} -f<br />
RewriteRule ^(.*) &quot;/cache/%{HTTP_HOST}/%{REQUEST_FILENAME}&quot; [L]</div></td></tr></tbody></table></div>
<p>Now to clarify a point you should not be caching images,css,js etc, we&#8217;re only covering dynamic content here, and the above are only examples to get you started, you should write rules to exclude certain content specific to your needs.</p>
<p>And before going of at any more of a tangent, here are some figures for you!</p>
<p><strong>ab -c 100 -n 500 -g ./saiweb-nocache-nogzip.bpl http://www.saiweb.co.uk/</strong></p>
<ul>
<li>No caching</li>
<li>No Gzip</li>
</ul>
<p>Server Hostname:        www.saiweb.co.uk<br />
Server Port:            80</p>
<p>Document Path:          /<br />
Document Length:        109086 bytes</p>
<p>Concurrency Level:      100<br />
Time taken for tests:   123.304 seconds<br />
Complete requests:      500<br />
Failed requests:        0<br />
Write errors:           0<br />
Total transferred:      54831652 bytes<br />
HTML transferred:       54692607 bytes<br />
Requests per second:    4.06 [#/sec] (mean)<br />
Time per request:       24660.828 [ms] (mean)<br />
Time per request:       246.608 [ms] (mean, across all concurrent requests)<br />
Transfer rate:          434.26 [Kbytes/sec] received</p>
<p>Connection Times (ms)<br />
min  mean[+/-sd] median   max<br />
Connect:       57  423 225.5    374    1837<br />
Processing:  2331 20460 16701.2  17232  115192<br />
Waiting:      270 1835 4155.8    576   38549<br />
Total:       2656 20882 16648.1  17692  115421</p>
<p>Percentage of the requests served within a certain time (ms)<br />
50%  17692<br />
66%  20700<br />
75%  24063<br />
80%  25770<br />
90%  35157<br />
95%  53328<br />
98%  82957<br />
99%  101497<br />
100%  115421 (longest request)</p>
<p><a href="http://www.saiweb.co.uk/wp-content/uploads/2010/08/saiweb-nocache-nogzip.png"><img class="aligncenter size-full wp-image-939" title="saiweb-nocache-nogzip" src="http://www.saiweb.co.uk/wp-content/uploads/2010/08/saiweb-nocache-nogzip.png" alt="" width="640" height="480" /></a></p>
<p>As can be seen as the number of requests grew the response time began to increase sharply and the overall performace of the site degrade, bare in mind these benchmarks are being made on my home DSL for the time being.</p>
<p><strong><br />
ab -c 100 -n 500 -g ./saiweb-cached.bpl http://www.saiweb.co.uk/</strong></p>
<p>Server Hostname:        www.saiweb.co.uk<br />
Server Port:            80</p>
<p>Document Path:          /<br />
Document Length:        109086 bytes</p>
<p>Concurrency Level:      100<br />
Time taken for tests:   79.212 seconds<br />
Complete requests:      500<br />
Failed requests:        0<br />
Write errors:           0<br />
Total transferred:      54889292 bytes<br />
HTML transferred:       54705058 bytes<br />
Requests per second:    6.31 [#/sec] (mean)<br />
Time per request:       15842.342 [ms] (mean)<br />
Time per request:       158.423 [ms] (mean, across all concurrent requests)<br />
Transfer rate:          676.70 [Kbytes/sec] received</p>
<p>Connection Times (ms)<br />
              min  mean[+/-sd] median   max<br />
Connect:       56  314 112.5    322    1341<br />
Processing:  2545 14721 5116.7  14296   36677<br />
Waiting:      216 1283 2228.2    351   13776<br />
Total:       2647 15035 5108.9  14624   36897</p>
<p>Percentage of the requests served within a certain time (ms)<br />
  50%  14624<br />
  66%  16675<br />
  75%  18058<br />
  80%  19093<br />
  90%  21608<br />
  95%  23489<br />
  98%  27684<br />
  99%  29972<br />
 100%  36897 (longest request)</p>
<p><a href="http://www.saiweb.co.uk/wp-content/uploads/2010/08/saiweb-cached1.png"><img src="http://www.saiweb.co.uk/wp-content/uploads/2010/08/saiweb-cached1.png" alt="" title="saiweb-cached" width="640" height="480" class="aligncenter size-full wp-image-941" /></a></p>
<p>A much more consistent line here, however as you can clearly see response times are roughly equal this is due to my DSL connection, so lets run these tests from somewhere with a little more bandwidth say the webserver itself using a loop back connection.</p>
<p><strong><br />
ab -c 100 -n 500 -g ./saiweb-cached.bpl http://www.saiweb.co.uk/</strong></p>
<p>Server Hostname:        www.saiweb.co.uk<br />
Server Port:            80</p>
<p>Document Path:          /<br />
Document Length:        109086 bytes</p>
<p>Concurrency Level:      100<br />
Time taken for tests:   0.262199 seconds<br />
Complete requests:      500<br />
Failed requests:        0<br />
Write errors:           0<br />
Total transferred:      54945406 bytes<br />
HTML transferred:       54761172 bytes<br />
Requests per second:    1906.95 [#/sec] (mean)<br />
Time per request:       52.440 [ms] (mean)<br />
Time per request:       0.524 [ms] (mean, across all concurrent requests)<br />
Transfer rate:          204642.27 [Kbytes/sec] received</p>
<p>Connection Times (ms)<br />
              min  mean[+/-sd] median   max<br />
Connect:        0    1   2.6      0       9<br />
Processing:     4   45  10.3     49      58<br />
Waiting:        1   38   9.9     41      50<br />
Total:          9   47   9.5     50      64</p>
<p>Percentage of the requests served within a certain time (ms)<br />
  50%     50<br />
  66%     51<br />
  75%     52<br />
  80%     52<br />
  90%     54<br />
  95%     56<br />
  98%     59<br />
  99%     61<br />
 100%     64 (longest request)</p>
<p><a href="http://www.saiweb.co.uk/wp-content/uploads/2010/08/saiweb-cached21.png"><img src="http://www.saiweb.co.uk/wp-content/uploads/2010/08/saiweb-cached21.png" alt="" title="saiweb-cached2" width="640" height="480" class="aligncenter size-full wp-image-943" /></a></p>
<p>In this case the response times rise and then plateau, no after which no further degradation occurs. </p>
<p><strong><br />
ab -c 100 -n 500 -g ./saiweb-nocache.bpl http://www.saiweb.co.uk/</strong></p>
<p>Server Hostname:        www.saiweb.co.uk<br />
Server Port:            80</p>
<p>Document Path:          /<br />
Document Length:        109086 bytes</p>
<p>Concurrency Level:      100<br />
Time taken for tests:   8.919565 seconds<br />
Complete requests:      500<br />
Failed requests:        0<br />
Write errors:           0<br />
Total transferred:      54680788 bytes<br />
HTML transferred:       54543000 bytes<br />
Requests per second:    56.06 [#/sec] (mean)<br />
Time per request:       1783.913 [ms] (mean)<br />
Time per request:       17.839 [ms] (mean, across all concurrent requests)<br />
Transfer rate:          5986.73 [Kbytes/sec] received</p>
<p>Connection Times (ms)<br />
              min  mean[+/-sd] median   max<br />
Connect:        0   14  30.7      0      85<br />
Processing:   246 1556 714.3   1365    6735<br />
Waiting:      241 1539 707.8   1360    6731<br />
Total:        250 1571 708.0   1368    6735</p>
<p>Percentage of the requests served within a certain time (ms)<br />
  50%   1368<br />
  66%   1451<br />
  75%   1550<br />
  80%   1700<br />
  90%   2658<br />
  95%   3121<br />
  98%   3491<br />
  99%   3638<br />
 100%   6735 (longest request)</p>
<p><a href="http://www.saiweb.co.uk/wp-content/uploads/2010/08/saiweb-cached3.png"><img src="http://www.saiweb.co.uk/wp-content/uploads/2010/08/saiweb-cached3.png" alt="" title="saiweb-cached3" width="640" height="480" class="aligncenter size-full wp-image-944" /></a></p>
<p>Oh dear of dear lets cut to the hard facts shall we?</p>
<p>We&#8217;ve gone from serving 1906.95 requests a second to 56.06 </p>
<ul>
<li>a 97.1% decrease in performance when removing caching</li>
<li>or a 3401.1% increase in performance when implementing caching</li>
</ul>
<p>We&#8217;ve gone from a response time of ~50ms to ~2000ms</p>
<ul>
<li>a 97.5% decrease in performance when removing caching</li>
<li>or a 4000% increase in performance when caching is on</li>
</ul>
<p>Then there is the CPU an memory overheads to consider, in this case a more prolonged test is required to gain the relevant sar data,<br />
now let me tell you that intentionally trying to get a test like this to run over a 10 minute period with the correct caching on is a lot harder than it sounds, the tests infact were completing far too quickly &#8230; </p>
<p>The problem I face is to make ab perform a long enough timed duration of results cached, I know for a fact uncached the server will fail under the load, so I have no way at present of grabbing this reliably, </p>
<p>what I can tell you is that this command: ab -c 300 -n 1000000 -g ./saiweb-cached.bpl http://www.saiweb.co.uk/</p>
<p>caused a load average of 2.96, 1.9,0.93 cache, and got as high as 21 before I killed it uncached.</p>
<p>Now I am going to bring this post to an end as it is getting quiet long, I plan to cover the following in a 2nd part.</p>
<ol>
<li>Opcode caching</li>
<li>CPU &#038; Memory usage, Cached vs. UNcached</li>
</ol>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.saiweb.co.uk%2Fhosting%2Fphp-caching-an-in-depth-review';
  addthis_title  = 'PHP+%26%23038%3B+Caching+an+in+depth+review.';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/hosting/php-caching-an-in-depth-review/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dissecting the hack &#8211; psychz.net</title>
		<link>http://www.saiweb.co.uk/hacking/dissecting-the-hack-psychz-net</link>
		<comments>http://www.saiweb.co.uk/hacking/dissecting-the-hack-psychz-net#comments</comments>
		<pubDate>Wed, 25 Aug 2010 19:12:39 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[brute]]></category>
		<category><![CDATA[force]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[psychz]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=913</guid>
		<description><![CDATA[For some background you may want to read the Original Story leading to this write up. The first thing that caught my attention was the fact Logwatch was reported login failures in the order of 1000&#8242;s from unassigned.psychz.net without an accompanying fail2ban email notifying me the offender had been banned. And this as it would [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.saiweb.co.uk%2Fhacking%2Fdissecting-the-hack-psychz-net"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.saiweb.co.uk%2Fhacking%2Fdissecting-the-hack-psychz-net&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>For some background you may want to read the <a href="http://www.saiweb.co.uk/hacking/when-fail2ban-fails-to-ban-dissecting-the-hack">Original Story</a> leading to this write up.</p>
<p>The first thing that caught my attention was the fact Logwatch was reported login failures in the order of 1000&#8242;s from unassigned.psychz.net without an accompanying fail2ban email notifying me the offender had been banned.</p>
<p>And this as it would turn out was because the attack was clearly intended to defeat such protection methods, this is due to the logged host being unassigned.psychz.net, when the authentication failure is logged, a reverse lookup is made within vsftpd to resolve the host this PTR record returns unassigned.psychz.net, and as such is written into the log.</p>
<p>fail2ban no uses regex to extract the host from the logs, and attempts to make a forward lookup on unassigned.psychz.net (A/CNAME records required) to resolve the ip address, and ban the offending ip, this is where things go awry.</p>
<p>psychz.net maintains their own DNS servers,</p>
<ol>
<li>DNS1.PSYCHZ.NET</li>
<li>DNS2.PSYCHZ.NET</li>
</ol>
<p>These provide a PTR but no A/CNAME record, as such fail2ban can not resolve an IP and the attacking ip is left to run their attack unhindered, see this log file: <a href="http://www.saiweb.co.uk/psychz-260710/fail2ban-grep.log">fail2ban name resolution failure log</a></p>
<p>The only way therefor to gain the attacking ip was to match the ftp connection times to those of the reported login failures using iptables to log all accesses to ftp, quickly get a count of connecting ip&#8217;s using:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">grep</span> kernel <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>messages <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $9}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/SRC=//'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">390 173.224.217.41</div></td></tr></tbody></table></div>
<p>A complete log can be found here: <a href="http://www.saiweb.co.uk/psychz-260710/iptables.log">iptables.log</a>, and a whois can be found here: <a href="http://www.saiweb.co.uk/psychz-260710/whois.txt">whois.txt</a></p>
<p>Disclosure steps taken:</p>
<ol>
<li>26/07/10 psychz support informed given deadline of 09/08/10 for resolution</li>
<li>Same day standard reply of &#8220;thanks for contacting support we are looking into this&#8221; &#8230;</li>
<li>27/07/0 Attacks continue 173.224.208.0/20 network black holed as a result
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-s</span> 173.224.208.0<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20</span> <span style="color: #660033;">-j</span> DROP</div></td></tr></tbody></table></div>
</li>
<li>09/08/10 deadline passes without update</li>
<li>25/08/10 this blog post published</li>
</ol>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.saiweb.co.uk%2Fhacking%2Fdissecting-the-hack-psychz-net';
  addthis_title  = 'dissecting+the+hack+%26%238211%3B+psychz.net';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/hacking/dissecting-the-hack-psychz-net/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cloud hosting &#8211; my views</title>
		<link>http://www.saiweb.co.uk/hosting/cloud-hosting-my-views</link>
		<comments>http://www.saiweb.co.uk/hosting/cloud-hosting-my-views#comments</comments>
		<pubDate>Wed, 25 Aug 2010 15:25:05 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[is]]></category>
		<category><![CDATA[pants]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=927</guid>
		<description><![CDATA[This blog entry here: http://rackerhacker.com/2010/08/25/a-nerds-perspective-on-cloud-hosting/ prompted me to write this blog post, after I realized I&#8217;d filled the comment field, without ending my &#8220;monologue&#8221;, anyway I thought it would be better to voice my opinions here, to you lot who are daft enough to read this blog. I think the problem mainly is the term [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.saiweb.co.uk%2Fhosting%2Fcloud-hosting-my-views"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.saiweb.co.uk%2Fhosting%2Fcloud-hosting-my-views&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>This blog entry here: <a href="http://rackerhacker.com/2010/08/25/a-nerds-perspective-on-cloud-hosting/">http://rackerhacker.com/2010/08/25/a-nerds-perspective-on-cloud-hosting/</a> prompted me to write this blog post, after I realized I&#8217;d filled the comment field, without ending my &#8220;monologue&#8221;, anyway I thought it would be better to voice my opinions here, to you lot who are daft enough to read this blog.</p>
<p>I think the problem mainly is the term &#8220;cloud&#8221; has been massively over marketed and possibly long since lost it&#8217;s original meaning, with providers trying to jump on the marketing bandwagon.</p>
<p>I&#8217;ve not made the jump to &#8220;the Cloud&#8221; yet, as frankly I can&#8217;t see a benefit to them over properly configured HA installations, for example I would much rather be using several pre-configured servers using RHCS to handle the migration of critical services (mySQL etc..).</p>
<p>I begin to see the benefits for large hosting providers, where customers what the power of a dedicated server but only pay for what they actually use, in this instance a provider ensures up time through live migration,</p>
<p>Some other misconceptions through over marketing I&#8217;d like to point out,</p>
<p>1) <strong>The &#8220;cloud&#8221; is not always on</strong></p>
<p>Don&#8217;t get me wrong it can be configured to be close, using distributed VM&#8217;s for your critical services (i.e. apache), coupling this with loadbalancing and clustering setups.</p>
<p>The misconception for most &#8220;end users&#8221; is that if you buy a single cloud instance, through magic/voodoo it will always be on 100% of the time!</p>
<p>Simply put if the hardware it was running on dies, it will go down, regardless of live migration measures in place, there will be downtime, do not pass go do not collect http 200 go directly to &gt; /dev/null</p>
<p>2) <strong>The &#8220;cloud&#8221; is not secure</strong></p>
<p>If you insist on putting your 5 year old joomla website on a cloud VM, it can and will become compromised quickly, security is only going to be as good as the configuration you have in place, you have mitigation measures such as</p>
<ul>
<li>selinux</li>
<li>webapp updates/patches</li>
<li>fail2ban/banhosts packages</li>
</ul>
<p>Whilst in itself a VM is largely seen as secure as it protects the host machine should the VM become compromised, it is not always the case, for instance there have been several occurrences of VMWare ESXI servers allowing code execution on the host (long since patched Don&#8217;t panic!), allowing attackers who have compromised a VM on the cloud to root the host machine and as a cascading effect every other VM instace on the box.</p>
<p>Let me point out a worst case scenario here:</p>
<ol>
<li>Hypervisor running on Host A with 30 Vm&#8217;s</li>
<li>Host A is part of a resilient set with live migration in place, Hosts B,C,D</li>
<li>VM A&#8217;s 5 year old joomla app is subject to an XSS bug, and an attacker places the r57 shell on the webapp,</li>
<li>attacker proceeds to deploy backdoors (i.e. meterpreter)</li>
<li>VM A is subject to remote code execution on host</li>
<li>Attacker compromises Host</li>
<li>Host A is now root&#8217;ed</li>
<li>Attacker forces Migration of VM A onto Host B</li>
<li>Host B rooted using same method</li>
<li>Rinse &amp; repeat for C &amp; D</li>
</ol>
<p>In summary, if you are looking at a cloud solution and your web presence is important take an informed decision from one of the larger providers, and <strong>NEVER EVER</strong> go with the cheapest option you could find, probably on ebay &#8230;</p>
<p>The cloud is not some magical being created by the hosting fairies that will take all your hosting and maintenance woes away, it may or may not be the right thing for your business / web app, and in certain instances can lower TCO, I for one will be sticking with my Cluster services and high Availability designs for a while yet.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.saiweb.co.uk%2Fhosting%2Fcloud-hosting-my-views';
  addthis_title  = 'Cloud+hosting+%26%238211%3B+my+views';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/hosting/cloud-hosting-my-views/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Data Mining &#8211; What hidden information do your photos contain?</title>
		<link>http://www.saiweb.co.uk/hacking/data-mining-what-hidden-information-do-your-photos-contain</link>
		<comments>http://www.saiweb.co.uk/hacking/data-mining-what-hidden-information-do-your-photos-contain#comments</comments>
		<pubDate>Mon, 09 Aug 2010 13:02:08 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[exif]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[jpeg]]></category>
		<category><![CDATA[mining.]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=921</guid>
		<description><![CDATA[Time was when a photo was just a captured moment in time, /end nostalgia Nowadays though what people do not realize is the shear amount of &#8220;extra&#8221; information is embedded in &#8220;that picture you just uploaded to flikr/facebook/photo bucket&#8221; especially if you are uploading from a &#8220;smart phone&#8221; as more and more people are now. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.saiweb.co.uk%2Fhacking%2Fdata-mining-what-hidden-information-do-your-photos-contain"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.saiweb.co.uk%2Fhacking%2Fdata-mining-what-hidden-information-do-your-photos-contain&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Time was when a photo was just a captured moment in time, /end nostalgia</p>
<p>Nowadays though what people do not realize is the shear amount of &#8220;extra&#8221; information is embedded in &#8220;that picture you just uploaded to flikr/facebook/photo bucket&#8221; especially if you are uploading from a &#8220;smart phone&#8221; as more and more people are now.</p>
<p>Most photos now contain GPS data embedded in them, this information will survive a resize / upload process, at the time of writing images tested from Facebook appear to have the exif data stripped out (thumbs up for facebook maybe), and it appears php GD by default replaces all EXIF data with it&#8217;s own (bug maybe?).</p>
<p>For non sanitized images however you can discern a wealth of information such as:</p>
<ol>
<li>Make of camera</li>
<li>Model of camera</li>
<li>Software version</li>
<li>Unix timestamp of time taken</li>
<li>DateTime stamp of time taken</li>
<li>Focal length used</li>
<li>Shutter speed</li>
<li>if flash used</li>
</ol>
<p>And if GPS is embedded:</p>
<ol>
<li>Longitude</li>
<li>Latitude</li>
<li>Altitude</li>
<li>GPS timestamp</li>
<li>Direction facing when photo taken</li>
</ol>
<p>There is yet more data such as the colour profile used, and image resolutions, in my tests photos taken from my iPhone 4 were within 10 meters of where I was actually standing when I took the picture, and in which direction I was facing when I took them.</p>
<p><strong>So one more thing to note in your applications &#8220;data sanity&#8221; is to strip EXIF tags from uploaded images, lest your contributors private details be leaked from your application.</strong></p>
<p>For example:</p>
<ol>
<li>User uploads photo for competition</li>
<li>Site uses resized photo on competition page to allow visitor voting</li>
<li>malicious user, saves image from site (or just uses the copy from thier browser cache), gets gps data from photo</li>
<li>malicious user now knows exact whereabouts photo was taken aswell as the time.</li>
</ol>
<p>And it doesn&#8217;t have to be a malicious user, it could be anyone/anything, if you want to check your images for EXIF data you can use my tool here: <a href="http://www.saiweb.co.uk/tools/exif_data.php">http://www.saiweb.co.uk/tools/exif_data.php</a></p>
<p>No data is stored, and images are deleted immediately after processing, you use this at your own risk however, if you misuse the tool you accept all liability for the legal action to follow, you have been warned.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.saiweb.co.uk%2Fhacking%2Fdata-mining-what-hidden-information-do-your-photos-contain';
  addthis_title  = 'Data+Mining+%26%238211%3B+What+hidden+information+do+your+photos+contain%3F';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/hacking/data-mining-what-hidden-information-do-your-photos-contain/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ESP Ghostscript 815.02: Unrecoverable error, exit code 255</title>
		<link>http://www.saiweb.co.uk/linux/esp-ghostscript-815-02-unrecoverable-error-exit-code-255</link>
		<comments>http://www.saiweb.co.uk/linux/esp-ghostscript-815-02-unrecoverable-error-exit-code-255#comments</comments>
		<pubDate>Mon, 26 Jul 2010 11:46:16 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[255]]></category>
		<category><![CDATA[exit]]></category>
		<category><![CDATA[ghostscript]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[imagick]]></category>
		<category><![CDATA[magic]]></category>
		<category><![CDATA[unrecoverable]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=908</guid>
		<description><![CDATA[ESP Ghostscript 815.02: Unrecoverable error, exit code 255 I got this issue today whilst running CentOS 5.4 x64 post investigation of images not being scaled when processing a specific PDF, the solution unfortunately is to build ghostscript and imagemagick from the latest sources. 12wget http://ghostscript.com/releases/ghostscript-8.71.tar.gz wget http://image_magick.veidrodis.com/image_magick/ImageMagick-6.6.3-0.tar.gz Unpack, configure, make &#038;&#038; make install To fix [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Fesp-ghostscript-815-02-unrecoverable-error-exit-code-255"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Fesp-ghostscript-815-02-unrecoverable-error-exit-code-255&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><strong>ESP Ghostscript 815.02: Unrecoverable error, exit code 255</strong></p>
<p>I got this issue today whilst running CentOS 5.4 x64 post investigation of images not being scaled when processing a specific PDF, the solution unfortunately is to build ghostscript and imagemagick from the latest sources.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>ghostscript.com<span style="color: #000000; font-weight: bold;">/</span>releases<span style="color: #000000; font-weight: bold;">/</span>ghostscript-<span style="color: #000000;">8.71</span>.tar.gz<br />
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>image_magick.veidrodis.com<span style="color: #000000; font-weight: bold;">/</span>image_magick<span style="color: #000000; font-weight: bold;">/</span>ImageMagick-6.6.3-<span style="color: #000000;">0</span>.tar.gz</div></td></tr></tbody></table></div>
<p>Unpack, configure, make &#038;&#038; make install</p>
<p>To fix compatibility with pear imagick</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>libMagickCore.so <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib64<span style="color: #000000; font-weight: bold;">/</span>libMagick.so.10<br />
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>libMagickWand.so <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib64<span style="color: #000000; font-weight: bold;">/</span>libWand.so.10<br />
<span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">gs</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">gs</span></div></td></tr></tbody></table></div>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Fesp-ghostscript-815-02-unrecoverable-error-exit-code-255';
  addthis_title  = 'ESP+Ghostscript+815.02%3A+Unrecoverable+error%2C+exit+code+255';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/esp-ghostscript-815-02-unrecoverable-error-exit-code-255/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When fail2ban fails to ban &#8211; Dissecting the hack</title>
		<link>http://www.saiweb.co.uk/hacking/when-fail2ban-fails-to-ban-dissecting-the-hack</link>
		<comments>http://www.saiweb.co.uk/hacking/when-fail2ban-fails-to-ban-dissecting-the-hack#comments</comments>
		<pubDate>Fri, 23 Jul 2010 10:23:52 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[brute]]></category>
		<category><![CDATA[dissecting]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[force]]></category>
		<category><![CDATA[hack]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=900</guid>
		<description><![CDATA[Most of the time when I review our log watches each morning I become enraged at the number of automated attacks, But ever so occasional I find one that frankly intrigues me. Today is just such an occasion where I have had multiple Brute force login attempts, the ingenious part is this attack has been [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.saiweb.co.uk%2Fhacking%2Fwhen-fail2ban-fails-to-ban-dissecting-the-hack"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.saiweb.co.uk%2Fhacking%2Fwhen-fail2ban-fails-to-ban-dissecting-the-hack&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Most of the time when I review our log watches each morning I become enraged at the number of automated attacks,</p>
<p>But ever so occasional I find one that frankly intrigues me.</p>
<p>Today is just such an occasion where I have had multiple Brute force login attempts, the ingenious part is this attack has been designed to bypass tools such as fail2ban, blockhosts etc, and this is how</p>
<ol>
<li>Attack is launched from <strong></strong></li>
<li><strong></strong> has PTR set for <strong></strong></li>
<li>Failed login attempts record <strong></strong> due to reverse lookup</li>
<li>There is no A record, attacker maintains their own nameservers for the <strong></strong></li>
<li>fail2ban notes failed logins, attempts to resolve <strong></strong> to an IP but fails, due to missing A record</li>
<li> Attacker can continue brute force attempts unhindered by being banned</li>
</ol>
<p>I am still reading into how to counter this and will update this post as I figure out how to work around it, it&#8217;s a very sneaky and frankly quiet clever method of working around most automated blacklisting/banning tools.</p>
<p><strong>Update 1:</strong><br />
One method I am trialing is the &#8220;log target&#8221; feature of iptables, in an attempt to match login failure times to the iptables log, I&#8217;ll post back with results.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables <span style="color: #660033;">-A</span> INPUT <span style="color: #660033;">-p</span> tcp <span style="color: #660033;">--dport</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span> <span style="color: #660033;">-j</span> LOG</div></td></tr></tbody></table></div>
<p>Outputs</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Jul 23 11:45:57 132 kernel: IN=eth0 OUT= MAC=&lt;mac addr&gt; SRC=&lt;connecitng ip&gt; DST=&lt;server ip&gt; LEN=64 TOS=0x00 PREC=0x00 TTL=55 ID=47423 DF PROTO=TCP SPT=3865 DPT=21 WINDOW=65535 RES=0x00 SYN URGP=0 <br />
Jul 23 11:45:57 132 kernel: IN=eth0 OUT= MAC=&lt;mac addr&gt; SRC=&lt;connecitng ip&gt; DST=&lt;server ip&gt; LEN=52 TOS=0x00 PREC=0x00 TTL=55 ID=45370 DF PROTO=TCP SPT=3865 DPT=21 WINDOW=65535 RES=0x00 ACK URGP=0 <br />
Jul 23 11:45:57 132 kernel: IN=eth0 OUT= MAC=&lt;mac addr&gt; SRC=&lt;connecitng ip&gt; DST=&lt;server ip&gt; LEN=52 TOS=0x00 PREC=0x00 TTL=55 ID=46896 DF PROTO=TCP SPT=3865 DPT=21 WINDOW=65535 RES=0x00 ACK URGP=0 <br />
Jul 23 11:46:01 132 kernel: IN=eth0 OUT= MAC=&lt;mac addr&gt; SRC=&lt;connecitng ip&gt; DST=&lt;server ip&gt; LEN=63 TOS=0x00 PREC=0x00 TTL=55 ID=38502 DF PROTO=TCP SPT=3865 DPT=21 WINDOW=65535 RES=0x00 ACK PSH URGP=0 <br />
Jul 23 11:46:02 132 kernel: IN=eth0 OUT= MAC=&lt;mac addr&gt; SRC=&lt;connecitng ip&gt; DST=&lt;server ip&gt; LEN=52 TOS=0x00 PREC=0x00 TTL=55 ID=32551 DF PROTO=TCP SPT=3865 DPT=21 WINDOW=65535 RES=0x00 ACK URGP=0 <br />
Jul 23 11:46:02 132 kernel: IN=eth0 OUT= MAC=&lt;mac addr&gt; SRC=&lt;connecitng ip&gt; DST=&lt;server ip&gt; LEN=52 TOS=0x00 PREC=0x00 TTL=55 ID=59735 DF PROTO=TCP SPT=3865 DPT=21 WINDOW=65535 RES=0x00 ACK URGP=0 <br />
Jul 23 11:46:04 132 kernel: IN=eth0 OUT= MAC=&lt;mac addr&gt; SRC=&lt;connecitng ip&gt; DST=&lt;server ip&gt; LEN=66 TOS=0x00 PREC=0x00 TTL=55 ID=23116 DF PROTO=TCP SPT=3865 DPT=21 WINDOW=65535 RES=0x00 ACK PSH URGP=0 <br />
Jul 23 11:46:07 132 kernel: IN=eth0 OUT= MAC=&lt;mac addr&gt; SRC=&lt;connecitng ip&gt; DST=&lt;server ip&gt; LEN=52 TOS=0x00 PREC=0x00 TTL=55 ID=40246 DF PROTO=TCP SPT=3865 DPT=21 WINDOW=65535 RES=0x00 ACK URGP=0</div></td></tr></tbody></table></div>
<p><strong>Update 2: Defeating the hack</strong></p>
<p>Now granted this would be a lot worse had the attacking IP been dynamic, fortunatly in this case it&#8217;s not</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">grep</span> kernel <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>messages <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $9}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/SRC=//'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">390 &nbsp; 173.XXX.XXX.XXX<br />
&nbsp; &nbsp; &nbsp; 4 195.XXX.XXX.XXX</div></td></tr></tbody></table></div>
<p>Ip&#8217;s have been masked to prevent anyone complaining or threatening legal action (again) for inferring you should block their ip / network range &#8230; and me firing off the obligatory &#8220;Well if you policed your own network I wouldn&#8217;t have to post this no would I&#8221; email, </p>
<p>Maybe I am just being Cynical in my &#8220;old&#8221; age &#8230;</p>
<p>Any how as you may have guess I&#8217;m black holing the ip with the 390 connection entries.</p>
<p><strong>Thanks</strong></p>
<p>Being as I spoke to a load of people during the course of this I realy can not remember who contributed what to this solution, so I&#8217;ll just have to thank you all let me know if you want a crediting link.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.saiweb.co.uk%2Fhacking%2Fwhen-fail2ban-fails-to-ban-dissecting-the-hack';
  addthis_title  = 'When+fail2ban+fails+to+ban+%26%238211%3B+Dissecting+the+hack';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/hacking/when-fail2ban-fails-to-ban-dissecting-the-hack/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enable logging in the SFTP subsystem</title>
		<link>http://www.saiweb.co.uk/linux/enable-logging-in-the-sftp-subsystem</link>
		<comments>http://www.saiweb.co.uk/linux/enable-logging-in-the-sftp-subsystem#comments</comments>
		<pubDate>Mon, 19 Jul 2010 17:48:05 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[sftp]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[sshd]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=897</guid>
		<description><![CDATA[This is something I have wanted to get working for some time now, and thanks to James P for passing me a note that as of OpenSSH 4.4 you can infact add command line args for the Subsystem configuration, which when combined with the (I assume new) logging functionality of the sftp-service allows you to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Fenable-logging-in-the-sftp-subsystem"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Fenable-logging-in-the-sftp-subsystem&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>This is something I have wanted to get working for some time now, and thanks to James P for passing me a note that as of OpenSSH 4.4 you can infact add command line args for the Subsystem configuration, which when combined with the  (I assume new) logging functionality of the sftp-service allows you to finally log what is occuring during an sftp session.</p>
<p>Note: Requires OpenSSH >= 4.4</p>
<p>Replace the susbsystem line in your /etc/ssh/sshd_config with</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Subsystem &nbsp; sftp&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>libexec<span style="color: #000000; font-weight: bold;">/</span>openssh<span style="color: #000000; font-weight: bold;">/</span>sftp-server <span style="color: #660033;">-f</span> LOCAL5 <span style="color: #660033;">-l</span> INFO</div></td></tr></tbody></table></div>
<p>Add the following to /etc/syslog.conf</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#sftp logging</span><br />
local5.<span style="color: #000000; font-weight: bold;">*</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>sftpd.log</div></td></tr></tbody></table></div>
<p>Restart the sshd and syslog services, try an sftp upload and review the logs @ /var/log/sftpd.log</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Fenable-logging-in-the-sftp-subsystem';
  addthis_title  = 'Enable+logging+in+the+SFTP+subsystem';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/enable-logging-in-the-sftp-subsystem/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux collection of handy scripts and one liners &#8211; Volume 1</title>
		<link>http://www.saiweb.co.uk/linux/linux-collection-of-handy-scripts-and-one-liners-volume-1</link>
		<comments>http://www.saiweb.co.uk/linux/linux-collection-of-handy-scripts-and-one-liners-volume-1#comments</comments>
		<pubDate>Thu, 15 Jul 2010 20:15:15 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[handy]]></category>
		<category><![CDATA[lhol]]></category>
		<category><![CDATA[liners]]></category>
		<category><![CDATA[one]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=892</guid>
		<description><![CDATA[Ever wanted / needed HTTPD or another service to run with a raised thread priority? Well you have a couple of options, add additional lines to the /etc/init.d script to change the nice level by adding additional lines on startup, or if you only need to do this on a temporary basis without restarting the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Flinux-collection-of-handy-scripts-and-one-liners-volume-1"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Flinux-collection-of-handy-scripts-and-one-liners-volume-1&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><strong>Ever wanted / needed HTTPD or another service to run with a raised thread priority?</strong></p>
<p>Well you have a couple of options, add additional lines to the /etc/init.d script to change the <a href="http://linux.about.com/library/cmd/blcmdl1_nice.htm">nice</a> level by adding additional lines on startup, or if you only need to do this on a temporary basis without restarting the service but need every thread to have a raised priority you can use a bash script</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<span style="color: #007800;">PIDS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> aux <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> httpd <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'grep'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>;<br />
<span style="color: #000000; font-weight: bold;">for</span> PID <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${PIDS[@]}</span><br />
<span style="color: #000000; font-weight: bold;">do</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; renice <span style="color: #000000;">20</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$PID</span><br />
<span style="color: #000000; font-weight: bold;">done</span></div></td></tr></tbody></table></div>
<p>You can renice between -20 and +20, depending on your requirements you can use this script in a cron job  to raise/lower priorities, change httpd for whatever service you want to change the thread priority for.</p>
<p><strong>Ever needed to check files were being accessed / written to?</strong></p>
<p>For this one you&#8217;re going to need the <a href="http://wiki.github.com/rvoicilas/inotify-tools">inotify-tools</a> package, specifically the inotifywait binary.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">inotifywait <span style="color: #660033;">-m</span> <span style="color: #660033;">--timefmt</span> <span style="color: #ff0000;">&quot;[%a %b %d %H:%M:%S %Y]&quot;</span> <span style="color: #660033;">--format</span> <span style="color: #ff0000;">&quot;%T [%e] %f&quot;</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">/</span>folder<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>watch</div></td></tr></tbody></table></div>
<p>An example usage is to ensure that caching is working correctly and that cache files are being used in place of processing PHP files, simply change &#8220;/folder/to/watch&#8221; to be your cache folder, and refresh a few pages.</p>
<p>All being well you&#8217;ll get an output similar to the following:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">y-tools-3.14)<br />
(root@132 BUZZ1) # /usr/local/bin/inotifywait -m --timefmt &quot;[%a %b %d %H:%M:%S %Y]&quot; --format &quot;%T [%e] %f&quot; -r /path/to/saiweb/wp-content/cache/supercache/*<br />
Setting up watches. &nbsp;Beware: since -r was given, this may take a while!<br />
Watches established.<br />
[Thu Jul 15 20:59:37 2010] [OPEN] index.html<br />
[Thu Jul 15 20:59:37 2010] [CLOSE_NOWRITE,CLOSE] index.html<br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] security<br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] vsftpd-chrooting-without-the-headache-allowing-shared-directories<br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] vsftpd-chrooting-without-the-headache-allowing-shared-directories<br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] the-zen-of-secured-shared-hosting-part-1<br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] the-zen-of-secured-shared-hosting-part-1<br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] php-security-considerations<br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] php-security-considerations<br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] antivirus-xp-2008-removal<br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] antivirus-xp-2008-removal<br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] suphplookupexception<br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] suphplookupexception<br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] honeypotting-for-viruses-statement-of-fees-200809<br />
[Thu Jul 15 21:00:08 2010] [OPEN,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] honeypotting-for-viruses-statement-of-fees-200809<br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] <br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR] security<br />
[Thu Jul 15 21:00:08 2010] [CLOSE_NOWRITE,CLOSE,ISDIR]</div></td></tr></tbody></table></div>
<p>As can be seen the re-write rules are redirecting users to the cached files/folders, in the example above I have used my <a href="http://wordpress.org/extend/plugins/wp-super-cache/">wp-supercache</a> folder.</p>
<p><strong>Ever needed to quickly get the memory usage of all threads for a service?</strong></p>
<p>You have two options for this a single line</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;ps -Ao rsz,comm,pid | grep &lt;process name&gt;</div></td></tr></tbody></table></div>
<p>or a bash function you can place in your ~/.bashrc</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> appmem<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;appmem &lt;string to filter&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;i.e. appmem httpd&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-Ao</span> rsz,<span style="color: #c20cb9; font-weight: bold;">comm</span>,pid <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$1</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>You can then call this (after logging back in again to load the .bashrc up) using</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">appmem &lt;filter&gt;</div></td></tr></tbody></table></div>
<p>replacing <filter> for instance with httpd will give you an output similar to the following:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">8032 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;6207<br />
33080 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 13828<br />
&nbsp;8552 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 14095<br />
28952 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 14102<br />
&nbsp;8540 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 14103<br />
30848 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 16741<br />
31296 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 16832<br />
30452 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 18439<br />
31044 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 19996<br />
30968 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 23287<br />
30356 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 23300<br />
25636 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 24553<br />
29712 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 24771<br />
25588 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 24777<br />
31632 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 24778<br />
25608 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 24796<br />
29716 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 24812<br />
28152 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 24813<br />
31684 httpd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 31291</div></td></tr></tbody></table></div>
<p>This shows memory in kilobytes, command, process id, you can see here I currently have 3mb/pid for each httpd process (due to <a href="http://www.saiweb.co.uk/linux/optimizing-apache-for-high-load-sites-part-3">my optimizations</a>, I highly recommend you read parts 1-3)</p>
<p><strong>Dump mysql data and compress on the fly</strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mysqldump -h &lt;host&gt; -u &lt;user&gt; -p &lt;dbname&gt; | bzip2 -c7 &gt; /path/to/dump.sql.bz2</div></td></tr></tbody></table></div>
<p>Self explanatory that one, pipes the output from mysqldump through bzip2 (which has better compression over gzip) and dumps it out to a file, if you _realy_ need a gziped file just replace bzip2 with gzip in the line above. </p>
<p><strong>Ever needed a selection of passwords generated?</strong></p>
<p>For this one you can use the <a href="http://linux.die.net/man/1/secpwgen">secpwgen</a></p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> pwgen<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">i</span>=<span style="color: #000000;">0</span>; i<span style="color: #000000; font-weight: bold;">&lt;</span>=<span style="color: #000000;">10</span>; i++ <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #007800;">pwd</span>=<span style="color: #000000; font-weight: bold;">`</span>secpwgen <span style="color: #660033;">-Aadhs</span> <span style="color: #000000;">10</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> ENTROPY <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span>;<span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>: <span style="color: #007800;">$pwd</span>&quot;</span>; <span style="color: #000000; font-weight: bold;">done</span>; &nbsp; <br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>Plant this in your ~/.basrc for a callable function that will genrate a selection of 10 secure passwords, handy when you&#8217;re fed up of 1337&#8242;ifying everything</p>
<p>example output:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">0: 4&gt;&amp;B.\2R+--<br />
1: )`WREEGZP{<br />
2: ^)3&quot;=F==|?0<br />
3: ?1/|;;GF-2<br />
4: [..///_([=AZ<br />
5: }^%RC~U8//L<br />
6: \//VNTQ[)-&gt;<br />
7: @HE5@3)A%?<br />
8: )|1C[BSIT*<br />
9: C[//X^W&lt;$G1<br />
10: EOQ#Y%NI&gt;-</div></td></tr></tbody></table></div>
<p>Modify the &#8220;-Aadhs&#8221; args to your taste.</p>
<p>This concludes Volume 1 and a very long post, please contribute your one liners / helper scripts via the comments.</p>
<p>Cheers</p>
<p>buzz</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Flinux-collection-of-handy-scripts-and-one-liners-volume-1';
  addthis_title  = 'Linux+collection+of+handy+scripts+and+one+liners+%26%238211%3B+Volume+1';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/linux-collection-of-handy-scripts-and-one-liners-volume-1/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>mySQL &gt;= 5.0.37 community profiling SQL queries.</title>
		<link>http://www.saiweb.co.uk/mysql/mysql-5-0-37-community-profiling-sql-queries</link>
		<comments>http://www.saiweb.co.uk/mysql/mysql-5-0-37-community-profiling-sql-queries#comments</comments>
		<pubDate>Thu, 15 Jul 2010 19:30:06 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[mySQL]]></category>
		<category><![CDATA[5.0.37]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[slow]]></category>
		<category><![CDATA[slow query]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=885</guid>
		<description><![CDATA[Whilst there indeed seems to be a veritable plethora of SQL profiling / benchmarking tools, most of them with insane commercial license fees (&#62;= $400 per annum on most) I have found it intriguing that as of mySQL community edition &#62;= 5.0.37 mySQL offers an inbuilt method for profiling SQL queries, as can be see [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.saiweb.co.uk%2Fmysql%2Fmysql-5-0-37-community-profiling-sql-queries"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.saiweb.co.uk%2Fmysql%2Fmysql-5-0-37-community-profiling-sql-queries&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Whilst there indeed seems to be a veritable plethora of SQL profiling / benchmarking tools, most of them with insane commercial license fees (&gt;= $400 per annum on most)</p>
<p>I have found it intriguing that as of mySQL community edition &gt;= 5.0.37 mySQL offers an inbuilt method for profiling SQL queries, as can be see <a href="http://dev.mysql.com/doc/refman/5.0/en/show-profiles.html">here</a> the downside is that this is session based, meaning it can only provide profiling information for the current connection, almost useless for trying to profile a running web app (that is without code modification to set profiling and harvest the data).</p>
<p>However it can be useful if you have a known slow query.</p>
<p>So lets work on the basis that we have a known slow SQL query we&#8217;d like profiling information for,</p>
<p>check to see if profiling is enabled:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> &nbsp;@@profiling;</div></td></tr></tbody></table></div>
<p>The returned value is generally 0 so lets enable it.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SET</span> profiling_history_size<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">100</span>;<br />
<span style="color: #993333; font-weight: bold;">SET</span> profiling<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span>;</div></td></tr></tbody></table></div>
<p>This tells mySQL to retain the profile of 100 queries in memory, and to enable profiling.</p>
<p>Now at this point this can also be used to diagnose slow loading datases, simply</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">USE</span> <span style="color: #66cc66;">&lt;</span>dbname<span style="color: #66cc66;">&gt;</span>;<br />
<span style="color: #993333; font-weight: bold;">SHOW</span> profiles;<br />
<span style="color: #993333; font-weight: bold;">SHOW</span> profile <span style="color: #993333; font-weight: bold;">FOR</span> <span style="color: #cc66cc;">1</span>;</div></td></tr></tbody></table></div>
<p>Upon running the above you will now be using your database and will see an output similar to</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">+----------+------------+-------------------+<br />
| Query_ID | Duration &nbsp; | Query &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |<br />
+----------+------------+-------------------+<br />
| &nbsp; &nbsp; &nbsp; &nbsp;1 | 0.00011400 | SELECT DATABASE() |<br />
| &nbsp; &nbsp; &nbsp; &nbsp;2 | 0.00048900 | show databases &nbsp; &nbsp;|<br />
| &nbsp; &nbsp; &nbsp; &nbsp;3 | 0.00026600 | show tables &nbsp; &nbsp; &nbsp; |<br />
+----------+------------+-------------------+</div></td></tr></tbody></table></div>
<p>Followed by</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">+----------------------+----------+<br />
| Status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Duration |<br />
+----------------------+----------+<br />
| starting &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0.000053 |<br />
| checking permissions | 0.000004 |<br />
| Opening tables &nbsp; &nbsp; &nbsp; | 0.000009 |<br />
| init &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0.000011 |<br />
| optimizing &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0.000004 |<br />
| executing &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000017 |<br />
| end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000003 |<br />
| end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000002 |<br />
| query end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000002 |<br />
| freeing items &nbsp; &nbsp; &nbsp; &nbsp;| 0.000005 |<br />
| logging slow query &nbsp; | 0.000002 |<br />
| cleaning up &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000002 |<br />
+----------------------+----------+</div></td></tr></tbody></table></div>
<p>In my case here nothing really eventful, lets assume for the moment you are using a wordpress database, and you have numerous posts</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> count<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">WHERE</span> ID <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">100</span><br />
<span style="color: #993333; font-weight: bold;">SELECT</span> count<span style="color: #66cc66;">&#40;</span>ID<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> wp_posts <span style="color: #993333; font-weight: bold;">WHERE</span> ID <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">100</span></div></td></tr></tbody></table></div>
<p>in my case I got the following results:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">0.00072600 | select count(*) from wp_posts where ID &amp;gt; 100<br />
0.00069900 | select count(ID) from wp_posts where ID &amp;gt; 100</div></td></tr></tbody></table></div>
<p>a simple demonstration showing the difference between a count() on an indexed field vs *, in this case the saving is ~4%.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SHOW</span> profiles;<br />
<span style="color: #993333; font-weight: bold;">SHOW</span> profile <span style="color: #993333; font-weight: bold;">FOR</span> query <span style="color: #66cc66;">&lt;</span>n<span style="color: #66cc66;">&gt;</span>;</div></td></tr></tbody></table></div>
<p>Will give you an output similar to:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">+--------------------+----------+<br />
| Status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | Duration |<br />
+--------------------+----------+<br />
| starting &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0.000079 |<br />
| Opening tables &nbsp; &nbsp; | 0.000014 |<br />
| System lock &nbsp; &nbsp; &nbsp; &nbsp;| 0.000005 |<br />
| Table lock &nbsp; &nbsp; &nbsp; &nbsp; | 0.000008 |<br />
| init &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | 0.000025 |<br />
| optimizing &nbsp; &nbsp; &nbsp; &nbsp; | 0.000012 |<br />
| statistics &nbsp; &nbsp; &nbsp; &nbsp; | 0.000049 |<br />
| preparing &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000012 |<br />
| executing &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000006 |<br />
| Sending data &nbsp; &nbsp; &nbsp; | 0.000461 |<br />
| end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000004 |<br />
| end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000003 |<br />
| query end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| 0.000003 |<br />
| freeing items &nbsp; &nbsp; &nbsp;| 0.000007 |<br />
| closing tables &nbsp; &nbsp; | 0.000005 |<br />
| logging slow query | 0.000003 |<br />
| cleaning up &nbsp; &nbsp; &nbsp; &nbsp;| 0.000003 |<br />
+--------------------+----------+<br />
17 rows in set (0.00 sec)</div></td></tr></tbody></table></div>
<p>this is very similar to a <a href="http://en.wikipedia.org/wiki/Strace">stack trace</a> you may run on a problematic script, or <a href="http://www.xdebug.org">xdebug</a> + <a href="http://code.google.com/p/webgrind/">webgrind</a>, and will gain futher insight into your SQL should <a href="http://dev.mysql.com/doc/refman/5.0/en/explain.html">EXPLAIN</a> no give you enough of an insight.</p>
<p>I&#8217;ll post more information on this as I get time to work with it more, this is still knew to me, and aside from knowing how to use it I know relatively little about this profiling functionality, please feel free to post references / examples in the comments.</p>
<p>Cheers</p>
<p>Buzz</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.saiweb.co.uk%2Fmysql%2Fmysql-5-0-37-community-profiling-sql-queries';
  addthis_title  = 'mySQL+%3E%3D+5.0.37+community+profiling+SQL+queries.';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/mysql/mysql-5-0-37-community-profiling-sql-queries/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql csv export scripting using TCL and expect</title>
		<link>http://www.saiweb.co.uk/linux/mysql-csv-export-scripting-using-tcl-and-expect</link>
		<comments>http://www.saiweb.co.uk/linux/mysql-csv-export-scripting-using-tcl-and-expect#comments</comments>
		<pubDate>Mon, 05 Jul 2010 15:06:15 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[mySQL]]></category>
		<category><![CDATA[csv]]></category>
		<category><![CDATA[expect]]></category>
		<category><![CDATA[tcl]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=880</guid>
		<description><![CDATA[I&#8217;ve no idea to this day why my bash script would not work with a CSV export from mysql by simply using mysql -e &#8220;SQL COMMAND HERE&#8221;. So I had to come up with a workaround quickly. This lead to using expect, scripting in this method can be used for numerous purposes, I am currently [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Fmysql-csv-export-scripting-using-tcl-and-expect"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Fmysql-csv-export-scripting-using-tcl-and-expect&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;ve no idea to this day why my bash script would not work with a CSV export from mysql by simply using mysql -e &#8220;SQL COMMAND HERE&#8221;.</p>
<p>So I had to come up with a workaround quickly.</p>
<p>This lead to using <a href="http://linux.die.net/man/1/expect">expect</a>, scripting in this method can be used for numerous purposes, I am currently in the process of writing a few test scripts using tcl and this package for pop,imap,smtp testing.</p>
<div class="codecolorer-container tcl default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="tcl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#!/usr/bin/expect -f</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> DB <span style="color: #483d8b;">&quot;&lt;database&gt;&quot;</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> USER <span style="color: #483d8b;">&quot;&lt;user&gt;&quot;</span><br />
<span style="color: #ff7700;font-weight:bold;">set</span> PASS <span style="color: #483d8b;">&quot;&lt;password&gt;&quot;</span><br />
<br />
spawn mysql -u <span style="color: #ff3333;">$USER</span> -p <span style="color: #ff3333;">$DB</span><br />
match_max <span style="color: #ff4500;">100000</span><br />
expect -exact <span style="color: #483d8b;">&quot;assword: &quot;</span><br />
send -- <span style="color: #483d8b;">&quot;$PASS<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">set</span> SQL <span style="color: #483d8b;">&quot;SELECT * INTO OUTFILE '/tmp/csvfile.csv' FROM table&quot;</span><span style="color: #66cc66;">;</span><br />
<br />
expect -exact <span style="color: #483d8b;">&quot;mysql&gt; &quot;</span><br />
send -- <span style="color: #483d8b;">&quot;$SQL;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><br />
expect -exact <span style="color: #483d8b;">&quot;mysql&gt; &quot;</span><br />
sent -- <span style="color: #483d8b;">&quot;exit;/r&quot;</span></div></td></tr></tbody></table></div>
<p>Pretty simple realy once you have the hang of it, you tell it what to expect and what to reply with, there are more advanced methods going on from here, including conditional sends based on response.</p>
<p>I&#8217;ll be covering those soon.</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Fmysql-csv-export-scripting-using-tcl-and-expect';
  addthis_title  = 'mysql+csv+export+scripting+using+TCL+and+expect';
  addthis_pub    = '';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/mysql-csv-export-scripting-using-tcl-and-expect/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.618 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-09-03 10:20:36 -->
<!-- Compression = gzip -->