<?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; sysadmin</title>
	<atom:link href="http://www.saiweb.co.uk/tag/sysadmin/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 – 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_8d810ea9b851ac6d560a076f71aab96a" style="width:900px; height:300px;"></div><script language="Javascript" type="text/javascript">
	WPFP(document).ready(function() {
		//load player
		$f("saiweb_8d810ea9b851ac6d560a076f71aab96a", "/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_c040e480ecd0849d74920d09f83c0a89" style="width:900px; height:300px;"></div><script language="Javascript" type="text/javascript">
	WPFP(document).ready(function() {
		//load player
		$f("saiweb_c040e480ecd0849d74920d09f83c0a89", "/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>Converting mySQL latin1 to utf8</title>
		<link>http://www.saiweb.co.uk/mysql/converting-mysql-latin1-to-utf8</link>
		<comments>http://www.saiweb.co.uk/mysql/converting-mysql-latin1-to-utf8#comments</comments>
		<pubDate>Tue, 14 Jul 2009 08:46:02 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[mySQL]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[converting]]></category>
		<category><![CDATA[iconv]]></category>
		<category><![CDATA[latin-1]]></category>
		<category><![CDATA[latin1]]></category>
		<category><![CDATA[multibyte]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[utf-8]]></category>
		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/?p=696</guid>
		<description><![CDATA[The problem We&#8217;ve all been in this position at some point, working for a company who wants to internationalize their website, and so their mySQL CMS data &#8230; But all is not so well as just using &#8216;SET NAMES utf8&#8242; and changing all &#8216;charset&#8217; on tables to utf8, You may fall foul of seeing content [...]]]></description>
			<content:encoded><![CDATA[<ul>
<strong>The problem</strong></ul>
<p>We&#8217;ve all been in this position at some point, working for a company who wants to internationalize their website, and so their mySQL CMS data &#8230;</p>
<p>But all is not so well as just using &#8216;SET NAMES utf8&#8242; and changing all &#8216;charset&#8217; on tables to utf8,</p>
<p>You may fall foul of seeing content like &#193;&pound;</p>
<p>This is due to the fact in this case the latin1 encoded £ has not properly been converted to utf8 and as such is not rendering correctly, this is true of most &#8216;multibyte&#8217; characters.</p>
<ul>
<strong>The solution</strong></ul>
<p>What you need to do is actually convert the character set to utf8, in order to do this your going to need to run it through a program you could use iconv if you are already familiar with it, however if your system has python installed you can grab a copy of my <a href="http://www.saiweb.co.uk/sysadmin">sysadmin</a> program which has iconv like functionality but is far more user friendly.</p>
<ul>
<strong>What you will need</strong></ul>
<ul>
<li>Text Editor (vi/nano/pico/emacs)</li>
<li>Python 2.4 or higher</li>
<li><a href="http://linux.about.com/od/commands/l/blcmdl1_sed.htm">SED</a> package</li>
<li><a href="http://www.saiweb.co.uk/sysadmin">Sysadmin program</a></li>
<li>mySQL</li>
</ul>
<ul>
<strong>Preparing the file</strong></ul>
<p>This assumes the database is currently using latin1, in theory this could be any encoding.</p>
<p>Get a dump of the database:</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">mysqldump <span style="color: #660033;">--set-character-set</span>=latin-<span style="color: #000000;">1</span> <span style="color: #660033;">--set-charset</span> <span style="color: #660033;">-u</span> user <span style="color: #660033;">-pPASSWORD</span> databasename <span style="color: #000000; font-weight: bold;">&gt;</span> databasename-latin1.sql</div></td></tr></tbody></table></div>
<p>Now you have to be aware of what you need to replace using SED, you can&#8217;t just replace all instances of &#8216;latin1&#8242; as <a href="http://en.wikipedia.org/wiki/Murphy%27s_law">Murphy&#8217;s law</a> being as it is means that somewhere there will be &#8216;latin1&#8242; in the physical content, especially for instance if I was using a mysql dump from this blog.</p>
<p>As such you need to replace the following:</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: #000000; font-weight: bold;">/*!</span><span style="color: #000000;">40101</span> SET NAMES latin1 <span style="color: #000000; font-weight: bold;">*/</span>;</div></td></tr></tbody></table></div>
<p>If your database dump is small enough (sub 100mb) you can edit this line directly in your text editor, alternatively you can do the following.</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;">cat</span> .<span style="color: #000000; font-weight: bold;">/</span>databasename-latin1.sql <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/SET NAMES latin1/SET NAMES utf8/g'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> tmp<br />
<span style="color: #c20cb9; font-weight: bold;">cat</span> .<span style="color: #000000; font-weight: bold;">/</span>tmp <span style="color: #000000; font-weight: bold;">&gt;</span> .<span style="color: #000000; font-weight: bold;">/</span>databasename-latin1.sql<br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> .<span style="color: #000000; font-weight: bold;">/</span>tmp</div></td></tr></tbody></table></div>
<p>Now you need to replace all instances of &#8216;CHARSET=latin1&#8242;</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;">cat</span> .<span style="color: #000000; font-weight: bold;">/</span>databasename-latin1.sql <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/CHARSET=latin1/CHARSET=utf8/g'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> tmp<br />
<span style="color: #c20cb9; font-weight: bold;">cat</span> .<span style="color: #000000; font-weight: bold;">/</span>tmp <span style="color: #000000; font-weight: bold;">&gt;</span> .<span style="color: #000000; font-weight: bold;">/</span>databasename-latin1.sql<br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> .<span style="color: #000000; font-weight: bold;">/</span>tmp</div></td></tr></tbody></table></div>
<p>Now we have to run the file through the charset converter</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">sysadmin <span style="color: #660033;">-c</span> iconv <span style="color: #660033;">-d</span> .<span style="color: #000000; font-weight: bold;">/</span>databasename-latin1.sql,latin-<span style="color: #000000;">1</span>,utf-<span style="color: #000000;">8</span></div></td></tr></tbody></table></div>
<p>If your sql dump is over 30mb, you will be prompted to confirm you wish to proceed, please remember that this will load the entire file into memory, so ensure you have enough available system memory before proceeding, I also suggest not running this on a production server.</p>
<p>If any characters could not be converted you will be alerted to their exact position within the file, from there you will either need to use sed to replace the character or use your text editor.</p>
<p>If all went well you now have ./databasename-latin1.sql.utf-8 (note the utf-8 extension), you now have a complete utf8 mySQL dump, all you need do now is import the dump.</p>
<p><strong>
<ul>Further reading</ul>
<p></strong></p>
<ol>
<li><a href="http://www.saiweb.co.uk/mysql/mysql-forcing-utf-8-compliance-for-all-connections">Force mySQL utf8 connections</a></li>
<li><a href="http://www.saiweb.co.uk/mysql/mysql-bash-backup-script">mySQL backup script</a></li>
</ol>
<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/mysql/converting-mysql-latin1-to-utf8" data-text="Converting mySQL latin1 to utf8" 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%2Fmysql%2Fconverting-mysql-latin1-to-utf8&#038;text=Converting%20mySQL%20latin1%20to%20utf8" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/mysql/converting-mysql-latin1-to-utf8/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</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>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>
		<item>
		<title>Linux &#8211; The sysadmin script &#8211; Part 1</title>
		<link>http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-1</link>
		<comments>http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-1#comments</comments>
		<pubDate>Wed, 09 Jul 2008 16:10:47 +0000</pubDate>
		<dc:creator>Buzz</dc:creator>
				<category><![CDATA[Bash Script]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bofh]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.saiweb.co.uk/uncategorized/linux-the-sysadmin-script-part-1</guid>
		<description><![CDATA[Prompted by the following remarks today &#8230; Kerm: &#8220;;) there is always an abbreviation in the CLI as all sysadmins are lazy feckers&#8221; Kerm: &#8220;Someone might think you actually do work occasionally, god forbid!&#8221; Sysadmins are NOT inherently lazy, we just know how to save time, and are quite adept at doing so &#8230;ok? You [...]]]></description>
			<content:encoded><![CDATA[<p>Prompted by the following remarks today &#8230;</p>
<p><a href="http://www.absolutech.co.uk">Kerm</a>: <em>&#8220;;) there is always an abbreviation in the CLI as all sysadmins are lazy feckers&#8221;</em></p>
<p><em><a href="http://www.absolutech.co.uk">Kerm</a>: &#8220;Someone might think you actually do work occasionally, god forbid!&#8221;</em></p>
<p>Sysadmins are <strong><span style="text-decoration: underline;">NOT</span></strong> inherently lazy, we just know how to save time, and are quite adept at doing so &#8230;ok?</p>
<p><strong>You cheeky sods!</strong></p>
<p>So let me clear up one instance in which I take a lot of information, and make it quickly and easily accessible using a &#8220;<em>Lazy feckers</em>&#8221; abbreviation &#8230;</p>
<p><span style="text-decoration: underline;"><strong>Be warned this is a very jaded write up, read on at your own peril.</strong></span></p>
<p>Right then, onto the point of this post, the sysadmin script part 1, this is going to cover how to check how many connections to a specific port you have on your server.</p>
<p>Trust me this becomes very useful when you have exhausted all other options when trying to figure out why your web server is running like a dog with no legs &#8230;</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">netstat -ant</div></td></tr></tbody></table></div>
<p>After running the above on your SSH session you will see lines, and lines &#8230; and yet more lines of network connection information, especially if you just run this on a busy server.</p>
<p>Example (colours added):</p>
<p><span style="color: #ff0000;">tcp</span> <span style="color: #009900;">0</span> <span style="color: #ffcc00;">0</span> <span style="color: #00cccc;">***.***.***.***:25</span> <span style="color: #6633ff;">***.***.***.***:32794</span> <span style="color: #666666;">ESTABLISHED</span></p>
<p>Key:</p>
<p><span style="color: #ff0000;">PROTOCOL</span> <span style="color: #009900;">Tx</span> <span style="color: #ffcc00;">Rx</span> <span style="color: #00cccc;">LOCALHOST:PORT</span> <span style="color: #6633ff;">FOREIGN_HOST:PORT </span> <span style="color: #666666;">CONNECTION STATE</span></p>
<p>From this information it&#8217;s pretty easy to spot this is an inbound SMTP connection.</p>
<p>(If you can&#8217;t see why, don&#8217;t worry it&#8217;s ok maybe it&#8217;s <a href="http://www.theregister.co.uk/2008/07/04/bofh_2008_episode_24/">genetic</a>)</p>
<p>Now this may be handy, but other than taking all this information and dumping it into a spreadsheet (god knows you love those spreadsheets !!! ), how are you going to figure out how many connections are occurring from that external host?</p>
<p>How infact are you going to be able to easily see how many total connections to that port you have ?!?!</p>
<p>Bash script, now for some history, Bash is the Bourne Again Shell, or as I like to think of it, it is the verb for what I will do to your head if you ask me what BASH / SSH / Shell is again &#8230;</p>
<p>Now create a directory:</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">mkdir ~/.sysadmin<br />
cd ~/.sysadmin</div></td></tr></tbody></table></div>
<p>Note the prefixing dot, this will create a &#8220;hidden&#8221; directory in your home directory (~), the reason for this is so you don&#8217;t have system admin script sat in your home directoy, as if you are like me, all sorts of crap moves in an out of that directory on a daily basis, and the last thing you want to do is to have to rummage through backups trying to find &#8220;<em>that script you wrote to diagnose connection problems a year ago</em>&#8220;.</p>
<p>The point is these scripts will become part of your workflow, once written they will rarely need updating, and should never be called directly, (I mean we&#8217;re lazy right? WTH do we want to be typing the full script path for? &#8230; oh yeh it saves time!).</p>
<p>In this case:</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">vi ~/.sysadmin/buzz.sh</div></td></tr></tbody></table></div>
<p>You can of course call your script whatever you want, and use any text editor you want, if you don&#8217;t like / know vi &#8230;</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 /></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 />
# Sysadmin script PART 1 http://www.saiweb.co.uk<br />
# Provided under the MIT license (http://www.opensource.org/licenses/mit-license.php)<br />
# © D.Busby<br />
function usage {<br />
echo &quot;Usage: portcon port&quot;;<br />
echo &quot;i.e. portcon 80&quot;;<br />
}<br />
function portcon {<br />
echo &quot;----- Active Connections For Port $1 -----&quot;;<br />
netstat -ant | grep &quot;ABC.DEF.HIJ.KLM:$1 &quot; | wc -l<br />
netstat -ant | grep &quot;ABC.DEF.HIJ.KLM:$1 &quot; | awk '{ print $5 }' &nbsp;| awk -F \: '{ print $1 &nbsp;}' | sort | uniq -c &nbsp;| sort -n<br />
}<br />
if [ -z &quot;$1&quot; ]; then<br />
usage;<br />
exit<br />
fi<br />
$1 $2</div></td></tr></tbody></table></div>
<p>Ok so the above code is provided with two functions usage and portcon.</p>
<p><strong>MAKE SURE YOU REPLACE &#8220;ABC.DEF.HIJ.KLM&#8221; WITH YOUR <span style="color: #00cccc;">LOCAL IP ADDRESS </span></strong></p>
<p>CHMOD this file to allow execution.</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">chmod +x ~/.sysadmin/buzz.sh</div></td></tr></tbody></table></div>
<p>Now edit your bashrc file.</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">vi ~/.bashrc</div></td></tr></tbody></table></div>
<p>And add the following:</p>
<p>alias buzz=&#8217;~/.sysadmin/buzz.sh&#8217;</p>
<p>Now exit (logout) your SSH session and log back in (or SU root &gt; SU your_user for testing).</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 /></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 ~]$ buzz<br />
Usage: portcon port<br />
i.e. portcon 80<br />
[buzz@buzz_srv ~]$</div></td></tr></tbody></table></div>
<p>Now run the portcon check &#8230;</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 /></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 ~]$ buzz portcon 80<br />
----- Active Connections For Port 80 -----<br />
505<br />
1 ***.***.***.***<br />
3 ***.***.***.***<br />
3 ***.***.***.***<br />
4 ***.***.***.***<br />
4 ***.***.***.***<br />
5 ***.***.***.***<br />
11 ***.***.***.***<br />
14 ***.***.***.***<br />
16 ***.***.***.***<br />
76 ***.***.***.***<br />
373 ***.***.***.***</div></td></tr></tbody></table></div>
<p>(Yes before you ask ***.***.***.*** does display the correct IP address, I have purposely removed them for security).</p>
<p>So, I have taken something that would of resulted in netstat output &gt; spreadsheet to formulas &gt; at a estimate 30mins a time analysis to something that now takes less than 5 seconds to type, and get the relevant output, for roughly the same initial effort (30 mins scripting time).</p>
<p>You could argue you can keep a spreadsheet pre-setup with the right formulas / pivot tables and just dump the data each time, well yes you could but that&#8217;s no where near as quick as this &#8230;</p>
<p>And no trying to convince me it is as quick and better than the script above, for</p>
<ol>
<li> You have to wait for excel to open the spreadsheet</li>
<li> You have to copy paste the data</li>
<li> You have to wait for excel to process the formulas</li>
</ol>
<p>If you have a machine that can do that in time equal to or less than the time it takes the script above to output the data, the only thing I have to say is, <strong>stop spending such a budget on desktops and get a better server.<br />
</strong></p>
<p>Final Thoughts:</p>
<p>This write up is in jest, and is intended to be read as such, the code and methods provided above are factual. etc &#8230;<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-1" data-text="Linux &#8211; The sysadmin script &#8211; Part 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-the-sysadmin-script-part-1&#038;text=Linux%20%26%238211%3B%20The%20sysadmin%20script%20%26%238211%3B%20Part%201" >Tweet</a></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.saiweb.co.uk/linux/linux-the-sysadmin-script-part-1/feed</wfw:commentRss>
		<slash:comments>0</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 13/41 queries in 0.028 seconds using apc
Object Caching 1760/1841 objects using apc
Content Delivery Network via Rackspace Cloud Files: cdn.saiweb.co.uk

Served from: www.saiweb.co.uk @ 2012-02-08 15:38:08 -->
