<?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 &#187; Linux</title>
	<atom:link href="http://www.saiweb.co.uk/tag/linux/feed" rel="self" type="application/rss+xml" />
	<link>http://www.saiweb.co.uk</link>
	<description>Ramblings of a Sys admin</description>
	<lastBuildDate>Mon, 06 Feb 2012 14:57:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Linux collection of handy scripts and one liners – Volume 2 (Warning: contains shortcuts)</title>
		<link>http://www.saiweb.co.uk/linux/linux-collection-of-handy-scripts-and-one-liners-%e2%80%93-volume-2-warning-contains-shortcuts</link>
		<comments>http://www.saiweb.co.uk/linux/linux-collection-of-handy-scripts-and-one-liners-%e2%80%93-volume-2-warning-contains-shortcuts#comments</comments>
		<pubDate>Mon, 26 Sep 2011 15:43:34 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[lhol]]></category>
		<category><![CDATA[liners]]></category>
		<category><![CDATA[one]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=1129</guid>
		<description><![CDATA[See if hosts are up using ping in range 60 -> 200 12345for i in {60..200}; do ping -c 1 -W 1 192.168.1.$i &#62; /dev/null; ([[ $? == 0 ]] &#38;&#38; echo &#34;$i UP&#34; &#124;&#124; echo &#34;$i DOWN&#34;); &#160;done 1 UP 2 DOWN 3 UP ... Note: for OSX use &#8220;ping -c 1 -t 1&#8243; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>See if hosts are up using ping in range 60 -> 200</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 />2<br />3<br />4<br />5<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">for i in {60..200}; do ping -c 1 -W 1 192.168.1.$i &gt; /dev/null; ([[ $? == 0 ]] &amp;&amp; echo &quot;$i UP&quot; || echo &quot;$i DOWN&quot;); &nbsp;done<br />
1 UP<br />
2 DOWN<br />
3 UP<br />
...</div></td></tr></tbody></table></div>
<p>Note: for OSX use &#8220;ping -c 1 -t 1&#8243;</p>
<p><strong>Chaining &#8220;UP&#8221; hosts for a quick (syn) port scan</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 />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">for i in {60..200}; do ping -c 1 -W 1 192.168.1.$i &gt; /dev/null; ({{ $? == 0 ]] &amp;&amp; nc -v -n -z -w1 192.168.1.$i 20-22); done<br />
(UNKNOWN) [192.168.1.1] 22 (ssh) open<br />
(UNKNOWN) [192.168.1.3] 22 (ssh) open</div></td></tr></tbody></table></div>
<p><strong>Recover from a bad mysql password set (Update mysql.users set password=&#8217;Iforgotawherestatemenlulz&#8217;)</strong></p>
<p>Assumes for every user there is an @localhost host, grabs the in memory password hash and resets</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">mysql -Bse 'Select distinct(user) from mysql.user;' | while read uname; do mysql -Bse &quot;show grants for '$uname'@'localhost';&quot; 2&gt;&amp;1 | grep IDENTIFIED | grep -v 'root' | grep -v 'ERROR' | sed 's|GRANT USAGE ON *.* TO ||g' | sed &quot;s|@'localhost' IDENTIFIED BY PASSWORD||g&quot; | awk '{print &quot;Update user set Password=&quot;$2&quot; where User=&quot;$1&quot;;&quot;}' | mysql mysql; done</div></td></tr></tbody></table></div>
<p>If you&#8217;ve run FLUSH PRIVILEGES; however you == b0ned.</p>
<p><strong>Quick substitute and run</strong></p>
<p>Command1:</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">ping -c 1 -t 1 192.168.1.1</div></td></tr></tbody></table></div>
<p>Opps that&#8217;s OSX synatx </p>
<p>Command2:</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">^-t 1^-W 1</div></td></tr></tbody></table></div>
<p>et voila corrected syntax.</p>
<p><strong>Shortcuts</strong></p>
<p>!! &#8211; Execute last command<br />
!ping &#8211; Execute last ping command, can be used to !any command just be careful.<br />
ctrl+r &#8211; reverse search, just start typing the cmd for it to search your history, hit tab to complete<br />
ctrl+a &#8211; jump to beginning of line<br />
ctrl+e &#8211; jump to end of the line</p>
<p><strong>cURL FU</strong></p>
<p>curl -I -L blahblah.tld &#8211; Run a HEAD and follow redirects (very handy for quicklooking @ bit.ly short URLS before hitting them in a browser).</p>
<p><strong>python FU</strong></p>
<p>python -m SimpleHTTPServer &#8211; serves the current `pwd` as a browseable directory (Very cool but VERY insecure)<br />
python -m cProfile script.py &#8211; generate trace stats for a script execution (Very handy for finding excessive loops)</p>
<p><strong>DNS Fu</strong></p>
<p>Wikipedia over DNS:</p>
<p>host -t txt fu.wp.dg.cx</p>
<p>fu.wp.dg.cx descriptive text &#8220;Fu may refer to: Fu (Technology, especially computer related) (used as a suffix) &#8211; relating to a person &#8211; Possessing superior skills in an art\; relating to an artifact &#8211; representing an expression of high art. code-fu, Perl-fu, C-fu, etc, Fu (literature),&#8221; &#8221; a Chinese genre of rhymed prose, Fu (kana), a symbol in Japanese syllabaries, Fu County, in Shaanxi, China, Fu Foundation&#8230; http://a.vu/w:Fu&#8221;</p>
<p>Useful on _some_ public wifi connections if you just want to look something up quick (dns is not always re-written).</p>
<p>Get all MX servers for a domain:</p>
<p>dig google.co.uk MX</p>
<p>; <<>> DiG 9.6.0-APPLE-P2 <<>> google.co.uk MX<br />
;; global options: +cmd<br />
;; Got answer:<br />
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64165<br />
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 4, ADDITIONAL: 4</p>
<p>;; QUESTION SECTION:<br />
;google.co.uk.			IN	MX</p>
<p>;; ANSWER SECTION:<br />
google.co.uk.		10800	IN	MX	10 google.com.s9a1.psmtp.com.<br />
google.co.uk.		10800	IN	MX	10 google.com.s9a2.psmtp.com.<br />
google.co.uk.		10800	IN	MX	10 google.com.s9b1.psmtp.com.<br />
google.co.uk.		10800	IN	MX	10 google.com.s9b2.psmtp.com.</p>
<p>;; AUTHORITY SECTION:<br />
google.co.uk.		59925	IN	NS	ns2.google.com.<br />
google.co.uk.		59925	IN	NS	ns3.google.com.<br />
google.co.uk.		59925	IN	NS	ns4.google.com.<br />
google.co.uk.		59925	IN	NS	ns1.google.com.</p>
<p>;; ADDITIONAL SECTION:<br />
ns1.google.com.		158334	IN	A	216.239.32.10<br />
ns2.google.com.		158334	IN	A	216.239.34.10<br />
ns3.google.com.		158741	IN	A	216.239.36.10<br />
ns4.google.com.		158334	IN	A	216.239.38.10</p>
<p>;; Query time: 68 msec<br />
;; SERVER:<br />
;; WHEN: Mon Sep 26 16:41:26 2011<br />
;; MSG SIZE  rcvd: 310</p>
<p><strong>mySQL FU</strong></p>
<p>in one line, take a database, in stream replace content and stream into another db.</p>
<p>mysqldump original_db | sed &#8216;s/content_or_regex_to_replace/content_or_backref_replacement/g&#8217; | mysql destination_db<br />
<span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/linux/linux-collection-of-handy-scripts-and-one-liners-%e2%80%93-volume-2-warning-contains-shortcuts" data-text="Linux collection of handy scripts and one liners – Volume 2 (Warning: contains shortcuts)" href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Flinux-collection-of-handy-scripts-and-one-liners-%25e2%2580%2593-volume-2-warning-contains-shortcuts&#038;text=Linux%20collection%20of%20handy%20scripts%20and%20one%20liners%20%E2%80%93%20Volume%202%20%28Warning%3A%20contains%20shortcuts%29" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/linux-collection-of-handy-scripts-and-one-liners-%e2%80%93-volume-2-warning-contains-shortcuts/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cloaking your web apps &#8211; The hooded Apache</title>
		<link>http://www.saiweb.co.uk/security/cloaking-your-web-apps-the-hooded-apache</link>
		<comments>http://www.saiweb.co.uk/security/cloaking-your-web-apps-the-hooded-apache#comments</comments>
		<pubDate>Mon, 25 Apr 2011 19:54:06 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Apache]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=1008</guid>
		<description><![CDATA[Go ahead and run 1curl -I http://www.saiweb.co.uk You will get 12345678HTTP/1.1 200 OK Date: Mon, 25 Apr 2011 19:33:29 GMT Server: Apache Vary: Accept-Encoding,Cookie Cache-Control: max-age=3, must-revalidate WP-Super-Cache: Served supercache file from PHP Connection: close Content-Type: text/html; charset=UTF-8 As an attacker looking to hit a web app, one of the first things you&#8217;re going to [...]]]></description>
			<content:encoded><![CDATA[<p>Go ahead and run</p>
<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">curl -I http://www.saiweb.co.uk</div></td></tr></tbody></table></div>
</p>
<p>You will get </p>
<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">HTTP/1.1 200 OK<br />
Date: Mon, 25 Apr 2011 19:33:29 GMT<br />
Server: Apache<br />
Vary: Accept-Encoding,Cookie<br />
Cache-Control: max-age=3, must-revalidate<br />
WP-Super-Cache: Served supercache file from PHP<br />
Connection: close<br />
Content-Type: text/html; charset=UTF-8</div></td></tr></tbody></table></div>
</p>
<p>As an attacker looking to hit a web app, one of the first things you&#8217;re going to want to look into is what version of web server is running, in this case you can see this blog in fact runs apache &#8230; but there is not much else to go on here is there.</p>
<p>That&#8217;s intentional, and by manual configuration changes I have put in place, this is not the case of a default LAMP install, take for instance, this snippet from another website,</p>
<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">Server: Apache/2.2.16 (Debian)<br />
X-Powered-By: PHP/5.2.14</div></td></tr></tbody></table></div>
</p>
<p>This already has given me a wealth of information to go on and begin prepping an attack, I now know the site is running php version 5.2.14 Apache version 2.2.16 and that the underlying OS is Debian.</p>
<p>See the dilemma? your default roll outs are just declaring their running versions to anyone willing to listen, so lets make it a little more stealthy.</p>
<p>First and foremost if you are using php, edit your php.ini and set 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">expose_php = off</div></td></tr></tbody></table></div>
<p>Now head into your httpd.conf and set 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ServerTokens prod</div></td></tr></tbody></table></div>
<p>and</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">ServerSignature off</div></td></tr></tbody></table></div>
<p>With these 3 simple steps all the headers will now return is Server: Apache this is the first step to shielding your app, I&#8217;ll be covering further steps as time allows.</p>
<p><span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/security/cloaking-your-web-apps-the-hooded-apache" data-text="Cloaking your web apps &#8211; The hooded Apache" href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Fsecurity%2Fcloaking-your-web-apps-the-hooded-apache&#038;text=Cloaking%20your%20web%20apps%20%26%238211%3B%20The%20hooded%20Apache" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/security/cloaking-your-web-apps-the-hooded-apache/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Linux collection of handy scripts and one liners &#8211; Volume 1.5 (Feedback edition)</title>
		<link>http://www.saiweb.co.uk/linux/linux-collection-of-handy-scripts-and-one-liners-volume-1-5-feedback-edition</link>
		<comments>http://www.saiweb.co.uk/linux/linux-collection-of-handy-scripts-and-one-liners-volume-1-5-feedback-edition#comments</comments>
		<pubDate>Fri, 15 Oct 2010 10:08:12 +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=963</guid>
		<description><![CDATA[Following reader feedback please see below for an updated version of Volume 1 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 [...]]]></description>
			<content:encoded><![CDATA[<p>Following reader feedback please see below for an updated version of Volume 1</p>
<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>
<p>Much cleaner script here again thanks to Matthew Ife.</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;">#!/bin/bash</span><br />
pgrep httpd <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> pid; <span style="color: #000000; font-weight: bold;">do</span> renice <span style="color: #660033;">-20</span> <span style="color: #007800;">$pid</span>; <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><span style="color: #c20cb9; font-weight: bold;">watch</span></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>Alternatively you can use the following approach contributed by Matthew Ife:</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">auditctl <span style="color: #660033;">-w</span> <span style="color: #000000; font-weight: bold;">/</span>some<span style="color: #000000; font-weight: bold;">/</span>path <span style="color: #660033;">-p</span> <span style="color: #c20cb9; font-weight: bold;">w</span></div></td></tr></tbody></table></div>
<p>This will persist for the duration of your ssh session and relevant log entries will appear in /var/log/audit/audit.log, admittedly with far more useful information than inotifywait, and does not require you to install additional packages.</p>
<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>Using a slightly modified line originally provided by Matthew Ife,</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: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>urandom <span style="color: #007800;">bs</span>=<span style="color: #000000;">2048</span> <span style="color: #007800;">count</span>=<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #660033;">-cd</span> ‘a-zA-Z0-<span style="color: #000000;">9</span>+<span style="color: #000000; font-weight: bold;">@</span>\<span style="color: #000000; font-weight: bold;">!</span>\$\<span style="color: #7a0874; font-weight: bold;">&#40;</span>\<span style="color: #7a0874; font-weight: bold;">&#41;</span>’ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-b1-15</span><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 generate 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">)S9esjccl?MMiC1</div></td></tr></tbody></table></div>
<p>If you want runtime variable length you could change to cut -1-$1 and then call pwgen 15 for example.</p>
<p><strong>Check mySQL myISAM fragmentation</strong></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;">USE</span> information_schema;<br />
<span style="color: #993333; font-weight: bold;">SELECT</span> CONCAT<span style="color: #66cc66;">&#40;</span>TABLE_SCHEMA<span style="color: #66cc66;">,</span><span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">,</span><span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span><span style="color: #66cc66;">,</span> ENGINE<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span>DATA_LENGTH<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> DATA_LENGTH<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span>INDEX_LENGTH<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> INDEX_LENGTH<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>DATA_LENGTH <span style="color: #66cc66;">+</span> INDEX_LENGTH<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1204</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> TOTAL_LENGTH<span style="color: #66cc66;">,</span>TABLE_ROWS<span style="color: #66cc66;">,</span> UPDATE_TIME<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>INDEX_LENGTH<span style="color: #66cc66;">/</span><span style="color: #66cc66;">&#40;</span>DATA_LENGTH <span style="color: #66cc66;">+</span> INDEX_LENGTH<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> INDEX_PER<span style="color: #66cc66;">,</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>DATA_LENGTH<span style="color: #66cc66;">/</span><span style="color: #66cc66;">&#40;</span>DATA_LENGTH <span style="color: #66cc66;">+</span> INDEX_LENGTH<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> DATA_PER<span style="color: #66cc66;">,</span> <span style="color: #66cc66;">&#40;</span>DATA_FREE<span style="color: #66cc66;">/</span>DATA_LENGTH<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> FRAG_RATIO <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #993333; font-weight: bold;">TABLES</span> <span style="color: #993333; font-weight: bold;">WHERE</span> ENGINE <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AND</span> DATA_LENGTH <span style="color: #66cc66;">&gt;=</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AND</span> <span style="color: #66cc66;">&#40;</span>DATA_FREE<span style="color: #66cc66;">/</span>DATA_LENGTH<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;=</span><span style="color: #cc66cc;">0.02</span> <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> FRAG_RATIO <span style="color: #993333; font-weight: bold;">DESC</span>;</div></td></tr></tbody></table></div>
<p>Gives you a very quick overview of make up of your myISAM tables and their fragmentation (Data free vs data length).</p>
<p><span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/linux/linux-collection-of-handy-scripts-and-one-liners-volume-1-5-feedback-edition" data-text="Linux collection of handy scripts and one liners &#8211; Volume 1.5 (Feedback edition)" href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Flinux-collection-of-handy-scripts-and-one-liners-volume-1-5-feedback-edition&#038;text=Linux%20collection%20of%20handy%20scripts%20and%20one%20liners%20%26%238211%3B%20Volume%201.5%20%28Feedback%20edition%29" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/linux-collection-of-handy-scripts-and-one-liners-volume-1-5-feedback-edition/feed</wfw:commentRss>
		<slash:comments>3</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[<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><span style="color: #c20cb9; font-weight: bold;">watch</span></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<span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/linux/linux-collection-of-handy-scripts-and-one-liners-volume-1" data-text="Linux collection of handy scripts and one liners &#8211; Volume 1" href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Flinux-collection-of-handy-scripts-and-one-liners-volume-1&#038;text=Linux%20collection%20of%20handy%20scripts%20and%20one%20liners%20%26%238211%3B%20Volume%201" >Tweet</a></span></p>
]]></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>/bin/sh: bad interpreter</title>
		<link>http://www.saiweb.co.uk/uncategorized/bin-sh-bad-interpreter</link>
		<comments>http://www.saiweb.co.uk/uncategorized/bin-sh-bad-interpreter#comments</comments>
		<pubDate>Mon, 01 Feb 2010 11:41:58 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bad]]></category>
		<category><![CDATA[interpreter]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=816</guid>
		<description><![CDATA[For security newer distros of RHEL and their derivatives an mounting /tmp with the noexec option. Now if you have ever had to clean up a compromised web app you can see why this makes a lot of sense, and if not here&#8217;s a quick example. Yours/Clients web app becomes compromised, running kernel has a [...]]]></description>
			<content:encoded><![CDATA[<p>For security newer distros of RHEL and their derivatives an mounting /tmp with the noexec option.</p>
<p>Now if you have ever had to clean up a compromised web app you can see why this makes a lot of sense, and if not here&#8217;s a quick example.</p>
<p>Yours/Clients web app becomes compromised, running kernel has a buffer overflow that can lead to privilege escalation, attack writes out their code and compiles in /tmp, then runs said app from /tmp creating a pseudo root level shell, aka you&#8217;ve just been root kitted.</p>
<p>However there are legitimate reasons for using /tmp to compile, well I say legitimate, what I in fact mean is things like pecl, which you use to install extensions like APC require this &#8230;</p>
<p>workaround:</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: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">TMPDIR</span>=<span style="color: #ff0000;">'/a/paTh/your/user/can/write/to'</span></div></td></tr></tbody></table></div>
<p>Failing that:</p>
<p><strong>service httpd stop</strong></p>
<p><strong>DO NOT ALLOW ANY WEBAPP ACCESS WHILE NOEXEC IS IN USE!</strong></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;">mount</span> -o,remount,rw,<span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<br />
pecl <span style="color: #c20cb9; font-weight: bold;">install</span> apc<br />
<span style="color: #c20cb9; font-weight: bold;">mount</span> -o,remount,rw,noexec <span style="color: #000000; font-weight: bold;">/</span>tmp</div></td></tr></tbody></table></div>
<p><strong>DO NOT REMOVE THE NOEXEC OPTION IN /ETC/FSTAB PERMANENTLY YOU WILL REGRET DOING SO</strong><span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/uncategorized/bin-sh-bad-interpreter" data-text="/bin/sh: bad interpreter" href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Funcategorized%2Fbin-sh-bad-interpreter&#038;text=%2Fbin%2Fsh%3A%20bad%20interpreter" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/uncategorized/bin-sh-bad-interpreter/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux – Generating file manifests and then checking them &#8211; Improved</title>
		<link>http://www.saiweb.co.uk/linux/linux-%e2%80%93-generating-file-manifests-and-then-checking-them-improved</link>
		<comments>http://www.saiweb.co.uk/linux/linux-%e2%80%93-generating-file-manifests-and-then-checking-them-improved#comments</comments>
		<pubDate>Tue, 29 Sep 2009 14:14:06 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[indication]]></category>
		<category><![CDATA[indicator]]></category>
		<category><![CDATA[manifest]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[progress]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=788</guid>
		<description><![CDATA[Following on from Linux – Generating file manifests and then checking them I was always getting the same questions &#8230; How long left on the manifest Buzz ? How long left on the verification Buzz ? And I HATE having to turn around an say &#8230; I don&#8217;t know &#8230; The problem with the usual [...]]]></description>
			<content:encoded><![CDATA[<p>Following on from <a href="http://www.saiweb.co.uk/linux/linux-generating-file-manifests-and-then-checking-them">Linux – Generating file manifests and then checking them</a> I was always getting the same questions &#8230;</p>
<p>How long left on the manifest Buzz ?<br />
How long left on the verification Buzz ?</p>
<p>And I <strong>HATE</strong> having to turn around an say &#8230; I don&#8217;t know &#8230;</p>
<p>The problem with the usual command line method is that it give no indication of progress, and by extension no indication that it was infact running and not &#8216;hung&#8217; &#8230;</p>
<p>As such I have now added the &#8216;manifest&#8217; command set to the <a href="http://www.saiweb.co.uk/sysadmin">Sysadmin toolset</a></p>
<p>The manifest command take two data types, the first is a folder path from which to build the file manifest from, the manifest itself is also compatible with the &#8220;md5sum &#8211;check&#8221; function.</p>
<p><div id="saiweb_e491d6e6e47ed8b6a4cffecfb7c36b05" style="width:900px; height:300px;"></div><script language="Javascript" type="text/javascript">
	WPFP(document).ready(function() {
		//load player
		$f("saiweb_e491d6e6e47ed8b6a4cffecfb7c36b05", "/wp-content/plugins/wordpress-flowplayer/flowplayer/gpl/flowplayer-3.1.5.swf", {
				plugins: {
  					 controls: {    					
      					
      					
      					
      					sliderGradient: 'none',
      					progressGradient: 'medium',
      					
      					
      					backgroundColor: '#141648',
      					
      					
      					backgroundGradient: 'none',
      					bufferGradient: 'none',
   						opacity:1.0
   						}
				},
			clip: {
					url:'http://content.screencast.com/users/D.Busby/folders/Jing/media/dd41bc92-17d3-4c34-8d46-80188f13aff2/00000337.mp4',
					autoPlay: false,
       				autoBuffering: false
				},
				canvas: {
					backgroundColor:''
				}})
			});</script>
				</p>
<p>The second is the path to the manifest itself, in this case the manifest command will verify each file against it&#8217;s entry in the manifest:</p>
<p><div id="saiweb_81c4462ba9e9327f29e3d2de99efd7de" style="width:900px; height:300px;"></div><script language="Javascript" type="text/javascript">
	WPFP(document).ready(function() {
		//load player
		$f("saiweb_81c4462ba9e9327f29e3d2de99efd7de", "/wp-content/plugins/wordpress-flowplayer/flowplayer/gpl/flowplayer-3.1.5.swf", {
				plugins: {
  					 controls: {    					
      					
      					
      					
      					sliderGradient: 'none',
      					progressGradient: 'medium',
      					
      					
      					backgroundColor: '#141648',
      					
      					
      					backgroundGradient: 'none',
      					bufferGradient: 'none',
   						opacity:1.0
   						}
				},
			clip: {
					url:'http://content.screencast.com/users/D.Busby/folders/Jing/media/2d3eb196-87ef-4464-982b-5b9481c000fe/00000338.mp4',
					autoPlay: false,
       				autoBuffering: false
				},
				canvas: {
					backgroundColor:''
				}})
			});</script>
				</p>
<p>At each point the command give you an indication of it&#8217;s current status, however this does come at a small cost, the script has no concept of the size of you console and as such will always render out the same number of character meaning if you console is not wide enough it will not render correctly, in the videos I have the console on a high resolution monitor as can be seen each video itself is 900 pixels wide.</p>
<p>This process is CPU intensive (20-45% on one core of a intel core2duo 2.8GHZ) and uses around 140KB of memory.<span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/linux/linux-%e2%80%93-generating-file-manifests-and-then-checking-them-improved" data-text="Linux – Generating file manifests and then checking them &#8211; Improved" href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Flinux-%25e2%2580%2593-generating-file-manifests-and-then-checking-them-improved&#038;text=Linux%20%E2%80%93%20Generating%20file%20manifests%20and%20then%20checking%20them%20%26%238211%3B%20Improved" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/linux-%e2%80%93-generating-file-manifests-and-then-checking-them-improved/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://content.screencast.com/users/D.Busby/folders/Jing/media/dd41bc92-17d3-4c34-8d46-80188f13aff2/00000337.mp4" length="6951906" type="video/mp4" />
<enclosure url="http://content.screencast.com/users/D.Busby/folders/Jing/media/2d3eb196-87ef-4464-982b-5b9481c000fe/00000338.mp4" length="7847114" type="video/mp4" />
		</item>
		<item>
		<title>Linux &#8211; The Sysadmin Script &#8211; Part 4</title>
		<link>http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-4</link>
		<comments>http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-4#comments</comments>
		<pubDate>Fri, 14 Nov 2008 09:31:23 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Bash Script]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/uncategorized/linux-the-sysadmin-script-part-4</guid>
		<description><![CDATA[In part 4, I am going to cover more of an improvement than anything else to part 3 Part 3 itself is not incorrect, it correctly takes a memory footprint for each process running, the same as VIRT in top &#8230; However in processes such as APACHE the VIRT memory is the size of all [...]]]></description>
			<content:encoded><![CDATA[<p>In part 4, I am going to cover more of an improvement than anything else to <a href="http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-3">part 3</a></p>
<p>Part 3 itself is not incorrect, it correctly takes a memory footprint for each process running, the same as VIRT in top &#8230;</p>
<p>However in processes such as APACHE the VIRT memory is the size of all shared libraries, as correctly shown by pmap &#8230;</p>
<p>So what does this mean realy?</p>
<p>The memory usage is infact the following VIRT + RSS, where RSS is the resident set size, the RSS is a representation of the memory in use by the PID, and VIRT is shared between the child processes.</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">[buzz@buzz_srv ~]# ps aux | grep httpd | grep -v 'grep'<br />
root &nbsp; &nbsp; 16378 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3024 ? &nbsp; &nbsp; &nbsp; &nbsp;Ss &nbsp; Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20088 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3304 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20101 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3304 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20756 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3312 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20759 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3300 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20790 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3284 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20792 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3312 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20798 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3308 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20804 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3308 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20886 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3304 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20906 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3300 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20907 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3308 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20912 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3304 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20915 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3312 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20959 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3304 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20969 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3300 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20994 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3320 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20995 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3288 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20996 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3320 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20997 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3320 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd<br />
apache &nbsp; 20999 &nbsp;0.0 &nbsp;0.1 148640 &nbsp;3296 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp;Nov13 &nbsp; 0:00 /usr/sbin/httpd</div></td></tr></tbody></table></div>
<p>As can be seen above the &#8216;VIRT&#8217; does not change between the child processes, where as the RSS does dependant on what the thread is doing at that time.</p>
<p>So below is an improved appmem function to allow for this:</p>
<div class="codecolorer-container bash 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 /></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;">&#123;</span><br />
&nbsp; &nbsp; &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; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: sysadmin appmem app_name i.e. (sysadmin appmem apache)&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">RRES</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</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> <span style="color: #ff0000;">&quot;$1&quot;</span> <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;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;$0&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $6}'</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">VRES</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</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> <span style="color: #ff0000;">&quot;$1&quot;</span> <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;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;$0&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $5}'</span><span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">COUNT</span>=<span style="color: #000000;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">VMEM</span>=<span style="color: #000000;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">RMEM</span>=<span style="color: #000000;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> RSS <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${RRES[@]}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">RMEM</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$RSS</span>+<span style="color: #007800;">$RMEM</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">done</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> VIRT <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${VRES[@]}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">VMEM</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$VIRT</span>+<span style="color: #007800;">$VMEM</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">COUNT</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$COUNT</span>+<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">done</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">VMEM</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$VMEM</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$COUNT</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">VMEM</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$VMEM</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1024</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">RMEM</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$RMEM</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1024</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$YELLOW</span> ----- MEMORY USAGE REPORT FOR '$1' ----- <span style="color: #007800;">$CLEAR</span>&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;PID Count: <span style="color: #007800;">$COUNT</span>&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Shared Mem usage: <span style="color: #007800;">$VMEM</span> MB&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Total Resident Set Size: <span style="color: #007800;">$RMEM</span> MB&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Mem/PID: <span style="color: #007800;">$(($RMEM/$COUNT)</span>) MB&quot;</span>;<br />
&nbsp; &nbsp; &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>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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;----- MEMORY USAGE REPORT FOR 'httpd' ----- <br />
PID Count: 41<br />
Shared Mem usage: 140 MB<br />
Total Resident Set Site: 95 MB<br />
Mem/PID: 2 MB</div></td></tr></tbody></table></div>
<p><span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-4" data-text="Linux &#8211; The Sysadmin Script &#8211; Part 4" href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Flinux-the-sysadmin-script-part-4&#038;text=Linux%20%26%238211%3B%20The%20Sysadmin%20Script%20%26%238211%3B%20Part%204" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-4/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Linux &#8211; The Sysadmin script &#8211; Part 3</title>
		<link>http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-3</link>
		<comments>http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-3#comments</comments>
		<pubDate>Wed, 12 Nov 2008 12:25:22 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Bash Script]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-3</guid>
		<description><![CDATA[PART 3 IS INACCURATE, THE BELOW SCRIPT IS FOR REFERENCE ONLY, IT HAS BEEN REPLACED IN PART 4 In part 3, I am going to cover a bash function that will allow you to profile the memory usage of any application by name. By adding the function below into your script you can execute a [...]]]></description>
			<content:encoded><![CDATA[<p><strong>PART 3 IS INACCURATE, THE BELOW SCRIPT IS FOR REFERENCE ONLY, IT HAS BEEN REPLACED IN <a href="http://www.saiweb.co.uk/uncategorized/linux-the-sysadmin-script-part-4">PART 4</a></strong></p>
<p>In part 3, I am going to cover a bash function that will allow you to profile the memory usage of any application by name.</p>
<p>By adding the function below into your script you can execute a command such as: sysadmin appmem apache</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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">function appmem {<br />
if [ -z &quot;$1&quot; ]; then<br />
echo &quot;Usage: sysadmin appmem app_name i.e. (sysadmin appmem apache)&quot;;<br />
else<br />
if [ -x '/usr/bin/pmap' ]; then<br />
APID=(`ps aux | grep &quot;$1&quot; | grep -v 'grep' | grep -v &quot;$0&quot; | awk '{print $2}'`);<br />
COUNT=0;<br />
AMEM=0<br />
for PID in ${APID[@]}<br />
do<br />
TMP=$((`pmap -x $PID | grep &quot;total&quot; | awk '{print $3}'`));<br />
AMEM=$(($AMEM+$TMP));<br />
COUNT=$(($COUNT+1));<br />
done<br />
AMEM=$(($AMEM/1024));<br />
echo -e &quot;$YELLOW ----- MEMORY USAGE REPORT FOR '$1' ----- $CLEAR&quot;;<br />
echo &quot;PID Count: $COUNT&quot;;<br />
echo &quot;Mem usage: $AMEM MB&quot;;<br />
echo &quot;Mem/PID: $(($AMEM/$COUNT)) MB&quot;;<br />
echo -e &quot;$RED&quot;<br />
echo -e &quot;For more information run: pmap -x $PID $CLEAR&quot;;<br />
else<br />
echo 'Could not execute /usr/bin/pmap ... aborting';<br />
exit;<br />
fi<br />
fi<br />
}</div></td></tr></tbody></table></div>
<p>Sample 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;span style=&quot;color: #ffcc00;&quot;&gt;----- MEMORY USAGE REPORT FOR 'apache' -----&lt;/span&gt;<br />
PID Count: 6<br />
Mem usage: 1134 MB<br />
Mem/PID: 189 MB<br />
&lt;span style=&quot;color: #ff0000;&quot;&gt;<br />
For more information run: pmap -x 123456&lt;/span&gt;</div></td></tr></tbody></table></div>
<p>You can of course replace &#8216;apache&#8217; with the application or daemon name you want to profile the memory usage of.</p>
<p>This script does require that pmap is installed, if the script can not find it, it will abort.</p>
<p>As always any problems, post a comment.</p>
<p>UPDATE: Apparently I need to point out that if you haven&#8217;t read <a href="http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-2">PART 2</a>! then the colored output will not work &#8230; That&#8217;s why this entry is titled part 3, it does assume a degree of competence on your part in realizing part&#8217;s 1 and 2 may just be required reading &#8230;</p>
<p><strong>NOTE: The above provides a complete memory footprint of the indvidual PID, the same as VIRT in top.</strong></p>
<p><strong> VIRT &#8212; Virtual Image (kb)<br />
* The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out.<br />
* VIRT = SWAP + RES </strong><span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-3" data-text="Linux &#8211; The Sysadmin script &#8211; Part 3" href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Flinux-the-sysadmin-script-part-3&#038;text=Linux%20%26%238211%3B%20The%20Sysadmin%20script%20%26%238211%3B%20Part%203" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-3/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>/usr/bin/ld: skipping incompatible /usr/lib/libcom_err.so when searching for -lcom_err</title>
		<link>http://www.saiweb.co.uk/linux/usrbinld-skipping-incompatible-usrliblibcom_errso-when-searching-for-lcom_err</link>
		<comments>http://www.saiweb.co.uk/linux/usrbinld-skipping-incompatible-usrliblibcom_errso-when-searching-for-lcom_err#comments</comments>
		<pubDate>Thu, 16 Oct 2008 10:02:28 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[configure]]></category>
		<category><![CDATA[libcom_err]]></category>
		<category><![CDATA[libcom_err.so]]></category>
		<category><![CDATA[skipping imcompatible]]></category>
		<category><![CDATA[x64]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/linux/usrbinld-skipping-incompatible-usrliblibcom_errso-when-searching-for-lcom_err</guid>
		<description><![CDATA[/usr/bin/ld: skipping incompatible /usr/lib/libcom_err.so when searching for -lcom_err his one has been bugging me for a couple of hours now, when trying to compile PHP on a 64bit OS &#8230; Simple put it&#8217;s a missing symlink, and the config script is trying to &#8220;failover&#8221; to the version is can find which is 32 bit &#8230; [...]]]></description>
			<content:encoded><![CDATA[<p><b>/usr/bin/ld: skipping incompatible /usr/lib/libcom_err.so when searching for -lcom_err</b></p>
<p>his one has been bugging me for a couple of hours now, when trying to compile PHP on a 64bit OS &#8230;</p>
<p>Simple put it&#8217;s a missing symlink, and the config script is trying to &#8220;failover&#8221; to the version is can find which is 32 bit &#8230;</p>
<p>ln -sf /lib64/libcom_err.so.2 /lib64/libcom_err.so</p>
<p>Et voila fixed!</p>
<p><span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/linux/usrbinld-skipping-incompatible-usrliblibcom_errso-when-searching-for-lcom_err" data-text="/usr/bin/ld: skipping incompatible /usr/lib/libcom_err.so when searching for -lcom_err" href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Fusrbinld-skipping-incompatible-usrliblibcom_errso-when-searching-for-lcom_err&#038;text=%2Fusr%2Fbin%2Fld%3A%20skipping%20incompatible%20%2Fusr%2Flib%2Flibcom_err.so%20when%20searching%20for%20-lcom_err" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/usrbinld-skipping-incompatible-usrliblibcom_errso-when-searching-for-lcom_err/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Linux &#8211; The Sysadmin script &#8211; Part 2</title>
		<link>http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-2</link>
		<comments>http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-2#comments</comments>
		<pubDate>Tue, 14 Oct 2008 08:40:55 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Bash Script]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[bofh]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-2</guid>
		<description><![CDATA[Part 2 has finally arrived &#8230;. don&#8217;t all cheer at once now &#8230; In part two I will cover how to run an IP range scan using bash script, and if the host can be pinged retrieve the MAC address of the connected host. Now bare in mind this script was written to run from [...]]]></description>
			<content:encoded><![CDATA[<p>Part 2 has finally arrived &#8230;. don&#8217;t all cheer at once now &#8230;</p>
<p>In part two I will cover how to run an IP range scan using bash script, and if the host can be pinged retrieve the MAC address of the connected host.</p>
<p>Now bare in mind this script was written to run from a MAC running OSX Leopard.</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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#!/bin/bash<br />
#colours<br />
function colours {<br />
CLEAR='\e[00m';<br />
GREEN='\e[0;32m';<br />
RED='\e[0;31m';<br />
YELLOW='\e[1;33m';<br />
}<br />
#ipscan<br />
function ipscan {<br />
IPS_START=1;<br />
IPS_END=254;<br />
IPS_RANGE=192.168.1.<br />
echo &quot;Now running IPSCAN $IPS_RANGE$IPS_START - $IPS_RANGE$IPS_END&quot;<br />
for ((i=$IPS_START;i&amp;lt;=$IPS_END;i+=1)); do<br />
RESULT=`ping -c 1 -t 1 $IPS_RANGE$i | grep &quot;bytes from&quot;`;<br />
if [ -z &quot;$RESULT&quot; ]; then<br />
echo -e &quot;$IPS_RANGE$i:$RED DEAD $CLEAR&quot;;<br />
# If you comment out the above to report just the alive hosts, bash gets a bit funny about not processing anything here, so uncomment the below to keep it happy<br />
#holder=$i;<br />
else<br />
MAC=`arp $IPS_RANGE$i | awk '{ print $4 }';`;<br />
echo -e &quot;$IPS_RANGE$i:$GREEN ALIVE $CLEAR ($MAC)&quot;;<br />
fi<br />
done<br />
}<br />
colours;<br />
$1 $2</div></td></tr></tbody></table></div>
<p>To make this work on your Linux distro replace -t in the ping command with -W and check the awk entry for the arp output, a display of (no) means that no ARP entries could be found for the host, and change the IP range to that of your network.</p>
<p>That&#8217;s it for this part, dump this is a file and chmod +x as useual and run with ./script.sh ipscan.<span style="float: left;" ><a class="twitter-share-button"  data-via="Saiweb" data-count="horizontal" data-related="Saiweb:David Busby" data-lang="en" data-url="http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-2" data-text="Linux &#8211; The Sysadmin script &#8211; Part 2" href="http://twitter.com/share?via=Saiweb&#038;count=horizontal&#038;related=Saiweb%3ADavid%20Busby&#038;lang=en&#038;url=http%3A%2F%2Fwww.saiweb.co.uk%2Flinux%2Flinux-the-sysadmin-script-part-2&#038;text=Linux%20%26%238211%3B%20The%20Sysadmin%20script%20%26%238211%3B%20Part%202" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-2/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using apc
Database Caching 21/64 queries in 0.080 seconds using apc
Object Caching 3001/3121 objects using apc
Content Delivery Network via Rackspace Cloud Files: cdn.saiweb.co.uk

Served from: www.saiweb.co.uk @ 2012-02-07 16:53:18 -->
