<?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>systemBash &#187; Code Samples</title>
	<atom:link href="http://systembash.com/tags/code-samples/feed/" rel="self" type="application/rss+xml" />
	<link>http://systembash.com</link>
	<description>Technology and System Administration</description>
	<lastBuildDate>Sat, 12 May 2012 13:13:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Simple Disk Benchmarking in Linux Using &#8216;dd&#8217;</title>
		<link>http://systembash.com/content/simple-disk-benchmarking-in-linux-using-dd/</link>
		<comments>http://systembash.com/content/simple-disk-benchmarking-in-linux-using-dd/#comments</comments>
		<pubDate>Wed, 21 Mar 2012 18:23:03 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[benchmarking]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=1256</guid>
		<description><![CDATA[A great way to do a real-world disk test on your linux system is with a program called dd. dd stands for data description and is used for copying data sources. A simple command to do real-world disk write test in linux is: 1dd bs=1M count=512 if=/dev/zero of=test conv=fdatasync This creates a file named &#8216;test&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>A great way to do a real-world disk test on your linux system is with a program called dd.</p>
<p>dd stands for data description and is used for copying data sources. </p>
<p>A simple command to do real-world disk write test in linux is:</p>
<div class="codecolorer-container text mac-classic" 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">dd bs=1M count=512 if=/dev/zero of=test conv=fdatasync</div></td></tr></tbody></table></div>
<p>This creates a file named &#8216;test&#8217; with all zeroes in it. The flag conv=fdatasync tells dd to sync the write to disk before it exits. Without this flag, dd will perform the write but some of it will remain in memory, not giving you an accurate picture of the true write performance of the disk. </p>
<p>A sample of the run is below, with a simple SATA disk:</p>
<div class="codecolorer-container text mac-classic" 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">[14:11][root@server:~]$ dd bs=1M count=512 if=/dev/zero of=test conv=fdatasync<br />
512+0 records in<br />
512+0 records out<br />
536870912 bytes (537 MB) copied, 5.19611 s, 103 MB/s</div></td></tr></tbody></table></div>
<p>Now, there is a major caveat for using dd for disk benchmarking. The first is that it only tests filesystem access. Depending on your filesystem (I&#8217;m looking at your <a href="http://en.wikipedia.org/wiki/ZFS">ZFS</a>) the file write may itself just load into memory for writing later down the road. The same with a RAID controller on the system. </p>
<p>A <em>much more accurate</em> way of performing a disk benchmark is to use tools specifically geared towards this task. It will write much more data over a longer period of time. <a href="http://www.coker.com.au/bonnie++/">Bonnie++</a> is a particularly useful tool for this purpose. </p>
<p>Now don&#8217;t forget to remove that test file. </p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/simple-disk-benchmarking-in-linux-using-dd/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Apache 2.4 Upgrade and the &#8220;Invalid Command &#8216;Order&#8217;&#8221; Error</title>
		<link>http://systembash.com/content/apache-2-4-upgrade-and-the-invalid-command-order-error/</link>
		<comments>http://systembash.com/content/apache-2-4-upgrade-and-the-invalid-command-order-error/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 15:14:43 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Configurations]]></category>
		<category><![CDATA[apache]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=1249</guid>
		<description><![CDATA[The new Apache 2.4 has been released a few weeks ago and I decided to use this version while installing a new server (I compiled it from scratch rather that using an rpm or deb). After using one of my tried and true Apache configuration files, I received this error on start: 12Starting httpd: AH00526: [...]]]></description>
			<content:encoded><![CDATA[<p>The new <a href="http://arstechnica.com/business/news/2012/02/apache-devs-release-version-24-first-major-update-in-six-years.ars">Apache 2.4 has been released</a> a few weeks ago and I decided to use this version while installing a new server (I compiled it from scratch rather that using an rpm or deb). </p>
<p>After using one of my tried and true Apache configuration files, I received this error on start:</p>
<div class="codecolorer-container text mac-classic" 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">Starting httpd: AH00526: Syntax error on line 104 of /usr/local/apache2/conf/httpd.conf:<br />
Invalid command 'Order', perhaps misspelled or defined by a module not included in the server configuration</div></td></tr></tbody></table></div>
<p>Common wisdom would imply that I should make sure the authz_host module is installed (LoadModule authz_host_module modules/mod_authz_host.so), however this just was not working.</p>
<p>Finally, I discovered that the Order command has been removed from Apache 2.4! According to the <a href="http://httpd.apache.org/docs/trunk/upgrading.html">upgrade notes for Apache 2.4</a>:</p>
<blockquote><p>In 2.2, access control based on client hostname, IP address, and other characteristics of client requests was done using the directives Order, Allow, Deny, and Satisfy.</p>
<p>In 2.4, such access control is done in the same way as other authorization checks, using the new module mod_authz_host. The old access control idioms should be replaced by the new authentication mechanisms, although for compatibility with old configurations, the new module mod_access_compat is provided.</p></blockquote>
<p><strong>Basically, the Order command is depreciated. </strong></p>
<p>In my case, I replaced the lines:</p>
<div class="codecolorer-container text mac-classic" 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">Order deny,allow<br />
Deny from all</div></td></tr></tbody></table></div>
<p>with:</p>
<div class="codecolorer-container text mac-classic" 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">Require all denied</div></td></tr></tbody></table></div>
<p>Also make sure both of these modules are loaded:</p>
<div class="codecolorer-container text mac-classic" 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">LoadModule authz_core_module modules/mod_authz_core.so<br />
LoadModule authz_host_module modules/mod_authz_host.so</div></td></tr></tbody></table></div>
<p>Easy enough, but just be aware that there are several configuration changes between 2.2 and 2.4 which render your old Apache configuration files unusable. </p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/apache-2-4-upgrade-and-the-invalid-command-order-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Easy CIDR Cheatsheet</title>
		<link>http://systembash.com/content/cidr-cheatsheet/</link>
		<comments>http://systembash.com/content/cidr-cheatsheet/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 14:38:50 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Configurations]]></category>
		<category><![CDATA[Other Code]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[cidr]]></category>
		<category><![CDATA[Classless Inter-Domain Routing]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=1202</guid>
		<description><![CDATA[Even though I've been working with <a href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing">Classless Inter-Domain Routing</a> (henceforth known as CIDR) for years now, I always need a bit up a help remember how many addresses are in each block and how many sub-blocks fit into larger blocks. I have the following printed out for easy reference, and here it is for your geeky enjoyment:

<pre>CIDR        Total number    Network             Description:
Notation:   of addresses:   Mask:
--------------------------------------------------------------
/0          4,294,967,296   0.0.0.0             Every Address
/1          2,147,483,648   128.0.0.0           128 /8 nets
/2          1,073,741,824   192.0.0.0           64 /8 nets
/3          536,870,912     224.0.0.0           32 /8 nets
/4          268,435,456     240.0.0.0           16 /8 nets
/5          134,217,728     248.0.0.0           8 /8 nets
/6          67,108,864      252.0.0.0           4 /8 nets
/7          33,554,432      254.0.0.0           2 /8 nets
/8          16,777,214      255.0.0.0           1 /8 net (Class A)
--------------------------------------------------------------
/9          8,388,608       255.128.0.0         128 /16 nets
/10         4,194,304       255.192.0.0         64 /16 nets
/11         2,097,152       255.224.0.0         32 /16 nets
/12         1,048,576       255.240.0.0         16 /16 nets
/13         524,288         255.248.0.0         8 /16 nets
/14         262,144         255.252.0.0         4 /16 nets
/15         131.072         255.254.0.0         2 /16 nets
/16         65,536          255.255.0.0         1 /16 (Class B)
--------------------------------------------------------------
/17         32,768          255.255.128.0       128 /24 nets
/19         16,384          255.255.192.0       64 /24 nets
/19         8,192           255.255.224.0       32 /24 nets
/20         4,096           255.255.240.0       16 /24 nets
/21         2,048           255.255.248.0       8 /24 nets
/22         1,024           255.255.252.0       4 /24 nets
/23         512             255.255.254.0       2 /24 nets
/24         256             255.255.255.0       1 /24 (Class C)
--------------------------------------------------------------
/25         128             255.255.255.128     Half of a /24
/26         64              255.255.255.192     Fourth of a /24
/27         32              255.255.255.224     Eighth of a /24
/28         16              255.255.255.240     1/16th of a /24
/29         8               255.255.255.248     5 Usable addresses
/30         4               255.255.255.252     1 Usable address
/31         2               255.255.255.254     Unusable
/32         1               255.255.255.255     Single host
--------------------------------------------------------------
Reserved Space:
	0.0.0.0/8	
	127.0.0.0/8
	192.0.2.0/24
	10.0.0.0/8
	172.16.0.0/12
	192.168.0.0/16
	169.254.0.0/16</pre>]]></description>
			<content:encoded><![CDATA[<p>Even though I&#8217;ve been working with <a href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing">Classless Inter-Domain Routing</a> (henceforth known as CIDR) for years now, I always need a bit up a help remember how many addresses are in each block and how many sub-blocks fit into larger blocks. I have the following printed out for easy reference, and here it is for your geeky enjoyment:</p>
<pre>CIDR        Total number    Network             Description:
Notation:   of addresses:   Mask:
--------------------------------------------------------------
/0          4,294,967,296   0.0.0.0             Every Address
/1          2,147,483,648   128.0.0.0           128 /8 nets
/2          1,073,741,824   192.0.0.0           64 /8 nets
/3          536,870,912     224.0.0.0           32 /8 nets
/4          268,435,456     240.0.0.0           16 /8 nets
/5          134,217,728     248.0.0.0           8 /8 nets
/6          67,108,864      252.0.0.0           4 /8 nets
/7          33,554,432      254.0.0.0           2 /8 nets
/8          16,777,214      255.0.0.0           1 /8 net (Class A)
--------------------------------------------------------------
/9          8,388,608       255.128.0.0         128 /16 nets
/10         4,194,304       255.192.0.0         64 /16 nets
/11         2,097,152       255.224.0.0         32 /16 nets
/12         1,048,576       255.240.0.0         16 /16 nets
/13         524,288         255.248.0.0         8 /16 nets
/14         262,144         255.252.0.0         4 /16 nets
/15         131.072         255.254.0.0         2 /16 nets
/16         65,536          255.255.0.0         1 /16 (Class B)
--------------------------------------------------------------
/17         32,768          255.255.128.0       128 /24 nets
/19         16,384          255.255.192.0       64 /24 nets
/19         8,192           255.255.224.0       32 /24 nets
/20         4,096           255.255.240.0       16 /24 nets
/21         2,048           255.255.248.0       8 /24 nets
/22         1,024           255.255.252.0       4 /24 nets
/23         512             255.255.254.0       2 /24 nets
/24         256             255.255.255.0       1 /24 (Class C)
--------------------------------------------------------------
/25         128             255.255.255.128     Half of a /24
/26         64              255.255.255.192     Fourth of a /24
/27         32              255.255.255.224     Eighth of a /24
/28         16              255.255.255.240     1/16th of a /24
/29         8               255.255.255.248     5 Usable addresses
/30         4               255.255.255.252     1 Usable address
/31         2               255.255.255.254     Unusable
/32         1               255.255.255.255     Single host
--------------------------------------------------------------
Reserved Space:
	0.0.0.0/8
	127.0.0.0/8
	192.0.2.0/24
	10.0.0.0/8
	172.16.0.0/12
	192.168.0.0/16
	169.254.0.0/16</pre>
<p>Of course I&#8217;m not the first one to come up with this. Modified based on the cheat sheet from <a href="http://old.tamasrepus.hotnudiegirls.com/pages/IPv4+CIDR+notation+cheat+sheet">Samat Jain</a>. </p>
<p>Let me know if you have any improvements or suggestions. </p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/cidr-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exporting Announcements from WHMCS</title>
		<link>http://systembash.com/content/exporting-announcements-from-whmcs/</link>
		<comments>http://systembash.com/content/exporting-announcements-from-whmcs/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 13:59:31 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[sample code]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[whmcs]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=1022</guid>
		<description><![CDATA[Doing some integration work with <a href="http://whmcs.com/">WHMCS</a>, I found the need to export some of the announcements into <a href="http://wordpress.org/">Wordpress</a>. Since there isn't any native implementation of this, I found the best way is to export it directly from the database. The PHP code to do this is fairly easy...]]></description>
			<content:encoded><![CDATA[<p>Doing some integration work with <a href="http://whmcs.com/">WHMCS</a>, I found the need to export some of the announcements into <a href="http://wordpress.org/">WordPress</a>. Since there isn&#8217;t any native implementation of this, I found the best way is to export it directly from the database. The PHP code to do this is fairly easy:</p>
<div class="codecolorer-container php mac-classic" 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 /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/path/to/whmcs/configuration.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db_host</span><span style="color: #339933;">,</span><span style="color: #000088;">$db_username</span><span style="color: #339933;">,</span><span style="color: #000088;">$db_password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM tblannouncements WHERE published='on' ORDER BY date DESC LIMIT 0,3&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$date</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$announcement</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;announcement&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>/support/announcements.php?id=<span style="color: #006699; font-weight: bold;">$id</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #006699; font-weight: bold;">$title</span>&lt;/a&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>If you wanted to make it more than 3 posts, just change the limit to 5 or 10 or whatever you wish. You can also change the ordering and add additional filters via more SQL statements. If you wanted to do a list, encapulate the code with &lt;ul&gt; and just make them &lt;li&gt; entries.</p>
<p>I&#8217;m using this code in a WordPress template but it would work equally as well in any other PHP based application. </p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/exporting-announcements-from-whmcs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What a Resilver Looks Like in ZFS (and a Bug and/or Feature)</title>
		<link>http://systembash.com/content/what-a-resilver-looks-like-in-zfs/</link>
		<comments>http://systembash.com/content/what-a-resilver-looks-like-in-zfs/#comments</comments>
		<pubDate>Sun, 15 May 2011 12:16:08 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[RAID]]></category>
		<category><![CDATA[zfs]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=974</guid>
		<description><![CDATA[At home I have an (admittedly small) ZFS array set up to experiment with this neat newish raid technology. I think it has been around long enough that it can be used in production, but I'm still getting used to the little bugs/features, and here is one that I just found.

After figuring out that I had 2 out of 3 of my 1TB Seagate Barracuda hard drives fail, I had to give the array up for a loss and test out my backup strategy. Fortunately it worked and there was no data loss. After receiving the replacement drives in from RMA, I rebuilt the ZFS array (using raidz again) and went along my merry way. After 6 months or so, I started getting some funky results from my other drive. Thinking it might have some issue as with the others, I removed the drive and ran Seatools on it (by the way, Seatools doesn't offer a 64-bit Windows version - what year is this?).

The drive didn't show any signs of failure, so I decided to wipe it and add it back into the array to see what happens. That, of course, is easier said than done.]]></description>
			<content:encoded><![CDATA[<p>At home I have an (admittedly small) <a href="http://en.wikipedia.org/wiki/ZFS">ZFS</a> array set up to experiment with this awesome newish <a href="http://en.wikipedia.org/wiki/RAID">RAID</a> technology. I think it has been around long enough that it can now be used in production, but I&#8217;m still getting used to the little bugs/features, and here is one that I just found.</p>
<p>After figuring out that I had 2 out of 3 of my 1TB Seagate Barracuda hard drives in the array fail, I had to give the entire array up for a loss and test out my backup strategy. Fortunately it worked and there was no data loss. After receiving the replacement drives in from Seagate, I rebuilt the ZFS array (using <a href="http://www.solarisinternals.com/wiki/index.php/ZFS_Best_Practices_Guide#Should_I_Configure_a_RAIDZ.2C_RAIDZ-2.2C_RAIDZ-3.2C_or_a_Mirrored_Storage_Pool.3F">raidz</a> again) and went along my merry way. After another 6 months or so, I started getting some funky results from my other drive. Thinking it might have some issue as with the others, I removed the drive and ran <a href="http://www.seagate.com/www/en-us/support/downloads/seatools">Seatools</a> on it (by the way, Seatools doesn&#8217;t offer a 64-bit Windows version &#8211; what year is this?).</p>
<p>The drive didn&#8217;t show any signs of failure, so I decided to wipe it and add it back into the array to see what happens. That, of course, is easier said than done.</p>
<p>One of the problems I ran into is that I am using <a href="http://www.ubuntu.com/">Ubuntu</a> and <a href="http://fuse.sourceforge.net/">fuse</a> to run zfs. Ubuntu has this nasty habit of changing around drive identifiers when USB devices are plugged in. So now when this drive is plugged in, it is on /dev/sde instead of /dev/sdd, which is now a USB attached drive. </p>
<p>No problem, I figure, I&#8217;ll offline the bad drive in the zpool and replace it with the new drive location. No such luck.</p>
<p>First I offlined the drive using <code class="codecolorer text mac-classic"><span class="text">zpool offline media /dev/sdd</span></code>:</p>
<div class="codecolorer-container text mac-classic" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dave@cerberus:~$ sudo zpool status<br />
&nbsp; pool: media<br />
&nbsp;state: DEGRADED<br />
status: One or more devices has been taken offline by the administrator.<br />
&nbsp; &nbsp; &nbsp; &nbsp; Sufficient replicas exist for the pool to continue functioning in a<br />
&nbsp; &nbsp; &nbsp; &nbsp; degraded state.<br />
action: Online the device using 'zpool online' or replace the device with<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'zpool replace'.<br />
&nbsp;scrub: none requested<br />
config:<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; NAME &nbsp; &nbsp; &nbsp; &nbsp;STATE &nbsp; &nbsp; READ WRITE CKSUM<br />
&nbsp; &nbsp; &nbsp; &nbsp; media &nbsp; &nbsp; &nbsp; DEGRADED &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raidz1-0 &nbsp;DEGRADED &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sdd &nbsp; &nbsp; OFFLINE &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sdb &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sdc &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0</div></td></tr></tbody></table></div>
<p>Now that it&#8217;s offline, I thought you should be able to detach it. No such luck &#8211; since it is a &#8216;primary&#8217; device of the zpool it does not allow you to remove it.</p>
<div class="codecolorer-container text mac-classic" 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">dave@cerberus:~$ sudo zpool detach media /dev/sdd<br />
cannot detach /dev/sdd: only applicable to mirror and replacing vdevs</div></td></tr></tbody></table></div>
<p>What they <em>want</em> you to do is replace the drive with another drive. This drive (the same drive, with all info wiped from it) is now on /dev/sde. I try to replace it:</p>
<div class="codecolorer-container text mac-classic" 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">dave@cerberus:~$ sudo zpool replace media /dev/sdd /dev/sde<br />
invalid vdev specification<br />
use '-f' to override the following errors:<br />
/dev/sde is part of active pool 'media'<br />
dave@cerberus:~$ sudo zpool replace -f media /dev/sdd /dev/sde<br />
invalid vdev specification<br />
the following errors must be manually repaired:<br />
/dev/sde is part of active pool 'media'</div></td></tr></tbody></table></div>
<p>Even with -f it doesn&#8217;t allow the replacement, because the system thinks that the drive is part of another pool.</p>
<p>So basically you are stuck if trying to test a replacement with a drive that already been used in the pool. I&#8217;m sure I could replace it with another 1TB disk but what is the point of that? </p>
<p>I ended up resolving the problem by removing the external USB drive, therefore putting the drive back into the original /dev/sdd slot. Without issuing any commands, the system now sees the drive as the old one, and starts resilvering the drive.</p>
<div class="codecolorer-container text mac-classic" 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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">root@cerberus:/home/dave# zpool status<br />
&nbsp; pool: media<br />
&nbsp;state: ONLINE<br />
status: One or more devices has experienced an unrecoverable error. &nbsp;An<br />
&nbsp; &nbsp; &nbsp; &nbsp; attempt was made to correct the error. &nbsp;Applications are unaffected.<br />
action: Determine if the device needs to be replaced, and clear the errors<br />
&nbsp; &nbsp; &nbsp; &nbsp; using 'zpool clear' or replace the device with 'zpool replace'.<br />
&nbsp; &nbsp;see: http://www.sun.com/msg/ZFS-8000-9P<br />
&nbsp;scrub: resilver in progress for 0h9m, 4.62% done, 3h18m to go<br />
config:<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; NAME &nbsp; &nbsp; &nbsp; &nbsp;STATE &nbsp; &nbsp; READ WRITE CKSUM<br />
&nbsp; &nbsp; &nbsp; &nbsp; media &nbsp; &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raidz1-0 &nbsp;ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sdd &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp;13 &nbsp;30.2G resilvered<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sdb &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sdc &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0</div></td></tr></tbody></table></div>
<p>It is interesting to see what it looks like from an i/o perspective. The system reads from the two good drives and writes to the new (bad) one. Using <code class="codecolorer text mac-classic"><span class="text">iostat -x</span></code>:</p>
<div class="codecolorer-container text mac-classic" 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">avg-cpu: &nbsp;%user &nbsp; %nice %system %iowait &nbsp;%steal &nbsp; %idle<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 29.77 &nbsp; &nbsp;0.00 &nbsp; 13.81 &nbsp; 32.81 &nbsp; &nbsp;0.00 &nbsp; 23.60<br />
<br />
Device: &nbsp; &nbsp; &nbsp; &nbsp; rrqm/s &nbsp; wrqm/s &nbsp; &nbsp; r/s &nbsp; &nbsp; w/s &nbsp; rsec/s &nbsp; wsec/s avgrq-sz avgqu-sz &nbsp; await &nbsp;svctm &nbsp;%util<br />
sda &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0.00 &nbsp; &nbsp; 0.00 &nbsp; &nbsp;0.80 &nbsp; &nbsp;0.00 &nbsp; &nbsp;33.60 &nbsp; &nbsp; 0.00 &nbsp; &nbsp;42.00 &nbsp; &nbsp; 0.01 &nbsp; 15.00 &nbsp;15.00 &nbsp; 1.20<br />
sdb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0.00 &nbsp; &nbsp; 0.00 &nbsp;625.00 &nbsp; &nbsp;0.00 108033.20 &nbsp; &nbsp; 0.00 &nbsp; 172.85 &nbsp; &nbsp; 0.56 &nbsp; &nbsp;0.90 &nbsp; 0.49 &nbsp;30.80<br />
sdc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0.00 &nbsp; &nbsp; 0.00 &nbsp;624.20 &nbsp; &nbsp;0.00 107828.40 &nbsp; &nbsp; 0.00 &nbsp; 172.75 &nbsp; &nbsp; 0.50 &nbsp; &nbsp;0.81 &nbsp; 0.47 &nbsp;29.60<br />
sdd &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0.00 &nbsp; &nbsp; 1.20 &nbsp; &nbsp;0.00 &nbsp;504.40 &nbsp; &nbsp; 0.00 107729.60 &nbsp; 213.58 &nbsp; &nbsp; 9.52 &nbsp; 18.85 &nbsp; 1.98 100.00</div></td></tr></tbody></table></div>
<p>It seems that ZFS is able to identify a hard drive by GID somehow but doesn&#8217;t automatically use it in the pool. This makes it so that you can&#8217;t test a drive by removing it, formatting it, and putting it into a new location. <strong>Basically, zfs assumes that your drives are always going to be in the same /dev location, which isn&#8217;t always true</strong>. As soon as you attach a USB drive in Ubuntu things are going to shift around.</p>
<p>After the resilver is complete, the zpool status is:</p>
<div class="codecolorer-container text mac-classic" 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">root@cerberus:/home/dave# zpool status<br />
&nbsp; pool: media<br />
&nbsp;state: ONLINE<br />
status: One or more devices has experienced an unrecoverable error. &nbsp;An<br />
&nbsp; &nbsp; &nbsp; &nbsp; attempt was made to correct the error. &nbsp;Applications are unaffected.<br />
action: Determine if the device needs to be replaced, and clear the errors<br />
&nbsp; &nbsp; &nbsp; &nbsp; using 'zpool clear' or replace the device with 'zpool replace'.<br />
&nbsp; &nbsp;see: http://www.sun.com/msg/ZFS-8000-9P<br />
&nbsp;scrub: resilver completed after 0h16m with 0 errors on Sun May 15 07:35:46 2011<br />
config:<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; NAME &nbsp; &nbsp; &nbsp; &nbsp;STATE &nbsp; &nbsp; READ WRITE CKSUM<br />
&nbsp; &nbsp; &nbsp; &nbsp; media &nbsp; &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raidz1-0 &nbsp;ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sdd &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp;13 &nbsp;50.0G resilvered<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sdb &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sdc &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
<br />
errors: No known data errors</div></td></tr></tbody></table></div>
<p>You can now clear the error with:</p>
<div class="codecolorer-container text mac-classic" 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">root@cerberus:/home/dave# zpool clear media<br />
root@cerberus:/home/dave#</div></td></tr></tbody></table></div>
<p>Zpool status now shows no errors:</p>
<div class="codecolorer-container text mac-classic" 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">root@cerberus:/home/dave# zpool status<br />
&nbsp; pool: media<br />
&nbsp;state: ONLINE<br />
&nbsp;scrub: resilver completed after 0h16m with 0 errors on Sun May 15 07:35:46 2011<br />
config:<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; NAME &nbsp; &nbsp; &nbsp; &nbsp;STATE &nbsp; &nbsp; READ WRITE CKSUM<br />
&nbsp; &nbsp; &nbsp; &nbsp; media &nbsp; &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raidz1-0 &nbsp;ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sdd &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp;50.0G resilvered<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sdb &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sdc &nbsp; &nbsp; ONLINE &nbsp; &nbsp; &nbsp; 0 &nbsp; &nbsp; 0 &nbsp; &nbsp; 0<br />
<br />
errors: No known data errors</div></td></tr></tbody></table></div>
<p>So now the question I have is this: <em>Are you able to manually update or remove the drive status somewhere in your system?</em> How did zfs know that this drive already had a pool installed on it? I zeroed the drive and verified with fdisk there were no partition on it. Is there a file somewhere on the system that stores this information, or is it written somewhere on the drive?</p>
<p>ZFS is great, but it still has some little issues like this that give me pause before using it in a production system. Then again, I suppose all massive disk array systems have their little quirks!</p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/what-a-resilver-looks-like-in-zfs/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Disabling The hald-addon-storage Service On CentOS/RedHat</title>
		<link>http://systembash.com/content/disabling-the-hald-addon-storage-service-on-centosredhat/</link>
		<comments>http://systembash.com/content/disabling-the-hald-addon-storage-service-on-centosredhat/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 16:13:53 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Configurations]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[daemon]]></category>
		<category><![CDATA[hald]]></category>
		<category><![CDATA[hardware access layer]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=961</guid>
		<description><![CDATA[The hald &#8211; Hardware Access Layer Daemon &#8211; runs several processes in order to keep track of what hardware is installed on your system. This includes polling USB Drives and &#8216;hot-swap&#8217; devices to check for changes along with a host of other tasks. You might see it running on your system as follows: 12342474 ? [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://linux.die.net/man/8/hald">hald</a> &#8211; <em>Hardware Access Layer Daemon</em> &#8211; runs several processes in order to keep track of what hardware is installed on your system. This includes polling USB Drives and &#8216;hot-swap&#8217; devices to check for changes along with a host of other tasks. </p>
<p>You might see it running on your system as follows:</p>
<div class="codecolorer-container text mac-classic" 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">2474 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp; &nbsp;0:00 &nbsp;\_ hald-runner<br />
2481 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp; &nbsp;0:00 &nbsp; &nbsp; &nbsp;\_ hald-addon-acpi: listening on acpid socket /var/run/acpid.socket<br />
2487 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp; &nbsp;0:00 &nbsp; &nbsp; &nbsp;\_ hald-addon-keyboard: listening on /dev/input/event0<br />
2495 ? &nbsp; &nbsp; &nbsp; &nbsp;S &nbsp; &nbsp; 41:47 &nbsp; &nbsp; &nbsp;\_ hald-addon-storage: polling /dev/hdc</div></td></tr></tbody></table></div>
<p>If your system is static and the devices do not change, you can actually disable this service using a policy entry. </p>
<p>Create a file in your policy directory, for example /etc/hal/fdi/policy/99-custom.fdi. Add the text:</p>
<div class="codecolorer-container xml mac-classic" 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 /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;deviceinfo</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;0.2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;device<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;match</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;storage.removable&quot;</span> <span style="color: #000066;">bool</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;remove</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;info.addons&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;strlist&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>hald-addon-storage<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/remove<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/match<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/device<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/deviceinfo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>Save and reload the hald using <code class="codecolorer text mac-classic"><span class="text">/etc/init.d/haldaemon restart</span></code>.</p>
<p>And you will find that service no longer is polling your hardware.</p>
<p>Of course to turn it back on, remove that policy entry and restart the haldaemon again, it will be back in service.</p>
<p><em>Solution Credit: <a href="http://www.linuxforums.org/forum/newbie/160675-solved-completely-disabling-hald-addon-storage-not-just-stop-polling.html">Linuxforums User cn77</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/disabling-the-hald-addon-storage-service-on-centosredhat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Experimenting with Pascal on Ubuntu</title>
		<link>http://systembash.com/content/experimenting-with-pascal-on-ubuntu/</link>
		<comments>http://systembash.com/content/experimenting-with-pascal-on-ubuntu/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 02:35:44 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Other Code]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[pascal]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=884</guid>
		<description><![CDATA[I&#8217;ve been busy lately on a number of projects, one of which is a programming class I am currently taking. The class itself is interesting, we are learning about the different types of programming languages. For our latest project, we were tasked with writing a simple program in Pascal. Pascal isn&#8217;t used too much any [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been busy lately on a number of projects, one of which is a programming class I am currently taking. The class itself is interesting, we are learning about the different types of programming languages. For our latest project, we were tasked with writing a simple program in <a href="http://en.wikipedia.org/wiki/Pascal_%28programming_language%29">Pascal</a>. Pascal isn&#8217;t used too much any more since it lacks some of the features that most modern languages have, but it is good to know at least a little bit about it in case you ever run across some old Pascal programs in the wild.</p>
<p>The syntax for pascal is a bit verbose, that is the main complaint about it. There are a number of others, but that is beyond the scope of this howto.</p>
<h2>Installing The Pascal Compiler on Ubuntu</h2>
<p>Installing Pascal in modern Ubuntu is a cinch. The <a href="http://www.freepascal.org/">Free Pascal Compiler</a>, or <a href="http://manpages.ubuntu.com/manpages/intrepid/man1/fpc.1.html">fpc</a>, is all that you need to get started. It works great on 32-bit or 64-bit systems. Install with:</p>
<div class="codecolorer-container text mac-classic" 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">sudo apt-get install fpc</div></td></tr></tbody></table></div>
<p>Any prerequisites will automatically download and install along with fpc. </p>
<h2>Getting Started in Pascal</h2>
<p>To test the compiler let&#8217;s start with a simple Hello World program. Open up hello.pas and enter:</p>
<div class="codecolorer-container pascal mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="pascal codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">program</span> Hello;<br />
<br />
<span style="color: #000000; font-weight: bold;">begin</span><br />
<br />
<span style="color: #000066;">Writeln</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'Hello World'</span><span style="color: #009900;">&#41;</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">end</span>.</div></td></tr></tbody></table></div>
<p>Compile with <code class="codecolorer text mac-classic"><span class="text">fpc hello.pas</span></code> and run:</p>
<div class="codecolorer-container text mac-classic" 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">dave@cerberus:~/Pascal$ ./hello <br />
Hello World</div></td></tr></tbody></table></div>
<h2>Selection Sort in Pascal</h2>
<p>Now that we&#8217;ve verified it is running, I&#8217;m going to show you the code that I wrote for my program. Basically we were asked to Selection Sort two arrays of varying length. Apparently one of the (bad) features of Pascal originally was that you needed to declare the length of the array which made it a pain to work with them. </p>
<p>In this situation it is just two arrays so it isn&#8217;t too bad. Enter your array by creating two text files arrayA.txt and arrayB.txt. One number per line. The source code for sort.pas is:</p>
<div class="codecolorer-container pascal mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><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 />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br /></div></td><td><div class="pascal codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">program</span> Sort;<br />
<br />
<span style="color: #000000; font-weight: bold;">var</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; A<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">array</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span>..<span style="color: #cc66cc;">10</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">of</span> <span style="color: #000066; font-weight: bold;">Integer</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; B<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">array</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span>..<span style="color: #cc66cc;">20</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">of</span> <span style="color: #000066; font-weight: bold;">Integer</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; F<span style="color: #339933;">:</span> Text;<br />
&nbsp; &nbsp; &nbsp; &nbsp; i<span style="color: #339933;">,</span>j<span style="color: #339933;">,</span>k<span style="color: #339933;">,</span>l<span style="color: #339933;">,</span>m<span style="color: #339933;">,</span>temp<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">Integer</span>;<br />
<br />
<span style="color: #000000; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">{Read in array A}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Assign<span style="color: #009900;">&#40;</span>F<span style="color: #339933;">,</span> <span style="color: #ff0000;">'arrayA.txt'</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; Reset<span style="color: #009900;">&#40;</span>F<span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; i<span style="color: #339933;">:=</span> <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #000000; font-weight: bold;">not</span> <span style="color: #000066;">EOF</span><span style="color: #009900;">&#40;</span>F<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #000000; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Inc<span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">Read</span><span style="color: #009900;">&#40;</span>F<span style="color: #339933;">,</span> A<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">end</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">{Read in array B}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Assign<span style="color: #009900;">&#40;</span>F<span style="color: #339933;">,</span> <span style="color: #ff0000;">'arrayB.txt'</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; Reset<span style="color: #009900;">&#40;</span>F<span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; j<span style="color: #339933;">:=</span> <span style="color: #cc66cc;">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #000000; font-weight: bold;">not</span> <span style="color: #000066;">EOF</span><span style="color: #009900;">&#40;</span>F<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #000000; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Inc<span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">Read</span><span style="color: #009900;">&#40;</span>F<span style="color: #339933;">,</span> B<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">end</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; i<span style="color: #339933;">:=</span><span style="color: #cc66cc;">10</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; j<span style="color: #339933;">:=</span><span style="color: #cc66cc;">20</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">{Print out the unsorted arrays}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'Unsorted Arrays:'</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'Array A:'</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> k<span style="color: #339933;">:=</span><span style="color: #cc66cc;">1</span> <span style="color: #000000; font-weight: bold;">to</span> i <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">Write</span><span style="color: #009900;">&#40;</span>A<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">' '</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'Array B:'</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> k<span style="color: #339933;">:=</span><span style="color: #cc66cc;">1</span> <span style="color: #000000; font-weight: bold;">to</span> j <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">Write</span><span style="color: #009900;">&#40;</span>B<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">' '</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'========================='</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'Sorting Arrays...'</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'========================='</span><span style="color: #009900;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">{Selection Sort Array A}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> l <span style="color: #339933;">:=</span> <span style="color: #cc66cc;">1</span> <span style="color: #000000; font-weight: bold;">to</span> i <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> m <span style="color: #339933;">:=</span> l <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #000000; font-weight: bold;">to</span> i <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: #000000; font-weight: bold;">if</span> A<span style="color: #009900;">&#91;</span>l<span style="color: #009900;">&#93;</span> &gt; A<span style="color: #009900;">&#91;</span>m<span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp <span style="color: #339933;">:=</span> A<span style="color: #009900;">&#91;</span>l<span style="color: #009900;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A<span style="color: #009900;">&#91;</span>l<span style="color: #009900;">&#93;</span> <span style="color: #339933;">:=</span> A<span style="color: #009900;">&#91;</span>m<span style="color: #009900;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; A<span style="color: #009900;">&#91;</span>m<span style="color: #009900;">&#93;</span> <span style="color: #339933;">:=</span> temp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">end</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">{Selection Sort Array B}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> l <span style="color: #339933;">:=</span> <span style="color: #cc66cc;">1</span> <span style="color: #000000; font-weight: bold;">to</span> j <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> m <span style="color: #339933;">:=</span> l <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span> <span style="color: #000000; font-weight: bold;">to</span> j <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: #000000; font-weight: bold;">if</span> B<span style="color: #009900;">&#91;</span>l<span style="color: #009900;">&#93;</span> &gt; B<span style="color: #009900;">&#91;</span>m<span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp <span style="color: #339933;">:=</span> B<span style="color: #009900;">&#91;</span>l<span style="color: #009900;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; B<span style="color: #009900;">&#91;</span>l<span style="color: #009900;">&#93;</span> <span style="color: #339933;">:=</span> B<span style="color: #009900;">&#91;</span>m<span style="color: #009900;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; B<span style="color: #009900;">&#91;</span>m<span style="color: #009900;">&#93;</span> <span style="color: #339933;">:=</span> temp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">end</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">{Print out the sorted arrays}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'Selection Sorted Arrays:'</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'Array A: '</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> k<span style="color: #339933;">:=</span><span style="color: #cc66cc;">1</span> <span style="color: #000000; font-weight: bold;">to</span> i <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">Write</span><span style="color: #009900;">&#40;</span>A<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">' '</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'Array B: '</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">for</span> k<span style="color: #339933;">:=</span><span style="color: #cc66cc;">1</span> <span style="color: #000000; font-weight: bold;">to</span> j <span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">Write</span><span style="color: #009900;">&#40;</span>B<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">' '</span><span style="color: #009900;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">WriteLn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">end</span>.</div></td></tr></tbody></table></div>
<p>Compile and run (ok to ignore the compile-time errors)</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:400px;"><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 /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dave@cerberus:~/Pascal$ fpc sort.pas <br />
Free Pascal Compiler version 2.4.0-2 [2010/03/06] for x86_64<br />
Copyright (c) 1993-2009 by Florian Klaempfl<br />
Target OS: Linux for x86-64<br />
Compiling sort.pas<br />
Linking sort<br />
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?<br />
73 lines compiled, 0.1 sec <br />
dave@cerberus:~/Pascal$ ./sort <br />
Unsorted Arrays:<br />
Array A:<br />
28 24 85 55 43 6 23 13 59 71 <br />
Array B:<br />
13 37 36 53 24 83 27 42 62 71 9 92 1 41 6 3 88 77 65 67 <br />
=========================<br />
Sorting Arrays...<br />
=========================<br />
Selection Sorted Arrays:<br />
Array A: <br />
6 13 23 24 28 43 55 59 71 85 <br />
Array B: <br />
1 3 6 9 13 24 27 36 37 41 42 53 62 65 67 71 77 83 88 92 <br />
dave@cerberus:~/Pascal$</div></td></tr></tbody></table></div>
<p>And there you have it. Compiling Pascal program on Ubuntu is an easy way to get your feet wet in programming. Pascal is a great beginner&#8217;s programming language, but if you want to learn more there are a number of great resources available for <a href="http://www.learn-programming.za.net/learn_pascal_programming.html">learning Pascal</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/experimenting-with-pascal-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Random Quotes to the Bash Login Screen</title>
		<link>http://systembash.com/content/adding-random-quotes-to-the-bash-login-screen/</link>
		<comments>http://systembash.com/content/adding-random-quotes-to-the-bash-login-screen/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 13:49:13 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[quotes]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=873</guid>
		<description><![CDATA[According to &#8220;official&#8221; system administrator rules and guidelines you shouldn&#8217;t be adding so-called vain scripts to the login prompt &#8211; only utilities that will add something useful to the system (for example, current system load, memory and disk usage, etc). However I have some systems that I frequently connect to and thought it would be [...]]]></description>
			<content:encoded><![CDATA[<p>According to &#8220;official&#8221; system administrator rules and guidelines you shouldn&#8217;t be adding so-called vain scripts to the login prompt &#8211; only utilities that will add something useful to the system (for example, current system load, memory and disk usage, etc). However I have some systems that I frequently connect to and thought it would be neat to add a random quote script to my bash login. That being said, this should only be done on &#8216;non-production&#8217; systems and adds a security vector so please be careful where you use this. </p>
<p>The goal of this is to add a little quote, at random, every time you log into your system. My thoughts were to do it not only as a little source of inspiration but also to add perspective to what I&#8217;m doing sitting in front of the computer all of the time. </p>
<p>Originally I was going to try to write the script solely in bash since it is so flexible (and just as a proof of concept) but dealing with RSS in bash isn&#8217;t exactly pretty and I just wanted to get this together as quick as possible. PHP makes parsing XML easy, there are a number of ways to accomplish it. I chose to use the ready-made script at <a href="http://rssphp.net/">rssphp.net</a> to do this, if you are curious about how you can handle this yourself using SimpleXML check out <a href="http://www.pixel2life.com/publish/tutorials/102/xml_parsing_using_built_in_libraries_in_php5/">this tutorial</a> over at Pixel2Life. The end result of my solution is a bash script calling a php script to grab the quote.</p>
<h2>The Code</h2>
<p>First create a file named <code class="codecolorer text mac-classic"><span class="text">/etc/update-motd.d/10-quote</span></code>. The name does not matter much &#8211; the number will decide what order the script is called in of all the scripts in /etc/update-motd.d. Do an <code class="codecolorer text mac-classic"><span class="text">ls</span></code> on that directory to see what all is being called when you log in. Add the following lines to this file, assuming you are placing your scripts in /etc/scripts/:</p>
<div class="codecolorer-container bash mac-classic" 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="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/sh</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span><br />
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>scripts<span style="color: #000000; font-weight: bold;">/</span>getquote.php<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span></div></td></tr></tbody></table></div>
<p><a href="http://rssphp.net/download/">Download v1 of rssphp</a> and extract it to the <code class="codecolorer text mac-classic"><span class="text">/etc/scripts/</span></code> directory. We will require that file in our php code.</p>
<p>Create the file <code class="codecolorer text mac-classic"><span class="text">/etc/scripts/getquote.php</span></code> and add the following:</p>
<div class="codecolorer-container php mac-classic" 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 /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'rss_php.php'</span><span style="color: #339933;">;</span> &nbsp; &nbsp;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$rss</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> rss_php<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.quotedb.com/quote/quote.php?action=random_quote_rss'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$rssitems</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$rss</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getItems</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rssitems</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// print_r($rssitems);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$rssitems</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' :: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$rssitems</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>I am using the RSS source from <a href="http://www.quotedb.com">QuoteDB</a> as the source of my quotes. Of all the places I checked (and I checked a lot) they seemed to have the most appropriate ones for this use. Feel free to use any source you wish &#8211; as long as the XML fields title/description hold the quote you will be able to use it. The RSS url was not obvious from the site and I had to do some digging to find it, in the end I am using <code class="codecolorer text mac-classic"><span class="text">http://www.quotedb.com/quote/quote.php?action=random_quote_rss</span></code>.</p>
<p>We also add the <em>if</em> statement to allow it to degrade nicely in case you have no network connectivity to the server. After a short period &#8211; a second or two &#8211; it will time out and let you log in. </p>
<p>The end result is a pretty quote in our motd:</p>
<div class="codecolorer-container text mac-classic" 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">Linux vps01.[redacted].com 2.6.18-2-pve #1 SMP Mon Feb 1 10:45:26 CET 2010 x86_64 GNU/Linux<br />
Ubuntu 10.04.1 LTS<br />
<br />
&quot;The absence of alternatives clears the mind marvelously.&quot; :: Henry Kissinger<br />
<br />
root@vps01:~#</div></td></tr></tbody></table></div>
<p>It should be pretty strait forward; let me know if you run into any problems!</p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/adding-random-quotes-to-the-bash-login-screen/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Find Out If A Twitter Username Exists Using PHP/JSON</title>
		<link>http://systembash.com/content/find-out-if-a-twitter-username-exists-using-php-json/</link>
		<comments>http://systembash.com/content/find-out-if-a-twitter-username-exists-using-php-json/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 03:32:11 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Social Media]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=861</guid>
		<description><![CDATA[I&#8217;ve been trying to grab a Twitter screenname that people continually register and do not use. Twitter eventually deletes it, but I suppose it is in high enough demand that someone else registers it right away (and then continues to never use it). Wrote up a quick and dirty php script to check the Twitter [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying to grab a Twitter screenname that people continually register and do not use. Twitter eventually deletes it, but I suppose it is in high enough demand that someone else registers it right away (and then continues to never use it). Wrote up a quick and dirty php script to check the <a href="http://dev.twitter.com/doc/get/users/show">Twitter API</a> to see if a screenname exists and if it doesn&#8217;t, shoot a short an email. I&#8217;ve been using <a href="http://www.changedetection.com/">changedetection</a> to roughly do the same thing but it has fallen short on two counts: the first is that it reports follower count changes, and second it only runs once a day and this hasn&#8217;t been fast enough for me to grab my desired screen name. </p>
<p>You can set this script to run via cron at any desired interval, I&#8217;ve set it to run every 30 minutes for me. Test with sample information to make sure it works under your setup. I&#8217;m using the default mail() function, and I also included some json decoding in there so you could also use this script to play around with decoding a user&#8217;s information in PHP.</p>
<div class="codecolorer-container php mac-classic" 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 />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 />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">/* Copyright (c) 2010 Dave Drager<br />
&nbsp;* <br />
&nbsp;* Permission is hereby granted, free of charge, to any person obtaining a copy<br />
&nbsp;* of this software and associated documentation files (the &quot;Software&quot;), to deal<br />
&nbsp;* in the Software without restriction, including without limitation the rights<br />
&nbsp;* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell<br />
&nbsp;* copies of the Software, and to permit persons to whom the Software is<br />
&nbsp;* furnished to do so, subject to the following conditions:<br />
&nbsp;* <br />
&nbsp;* The above copyright notice and this permission notice shall be included in<br />
&nbsp;* all copies or substantial portions of the Software.<br />
&nbsp;* <br />
&nbsp;* THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br />
&nbsp;* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br />
&nbsp;* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE<br />
&nbsp;* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br />
&nbsp;* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,<br />
&nbsp;* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN<br />
&nbsp;* THE SOFTWARE.<br />
&nbsp;*/</span><br />
<br />
<span style="color: #666666; font-style: italic;">/* README<br />
&nbsp;* This is a simple script to check a username on Twitter and send a short email<br />
&nbsp;* if it is not found. It's the simplest way I found to do this. Using the <br />
&nbsp;* sample code you could also modify it simply to do something with a <br />
&nbsp;* found username as well. Details are in the $json_output array. Enjoy <br />
&nbsp;*/</span><br />
<br />
<span style="color: #666666; font-style: italic;">// fill in these 2 variables below</span><br />
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;someusername&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$notifyemail</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;your_email@address&quot;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// this is needed otherwise file_get_contents errors out</span><br />
<span style="color: #990000;">error_reporting</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$url</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://api.twitter.com/1/users/show.json?screen_name=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$username</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$json</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$http_response_header</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;HTTP/1.1 404 Not Found&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//echo &quot;Screen name not taken!\n&quot;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$to</span> &nbsp; &nbsp; &nbsp;<span style="color: #339933;">=</span> <span style="color: #000088;">$notifyemail</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Screen name now available - '</span><span style="color: #339933;">.</span><span style="color: #000088;">$username</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'The screen name '</span><span style="color: #339933;">.</span><span style="color: #000088;">$username</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' is now available on Twitter.'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'From: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$notifyemail</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'-f '</span><span style="color: #339933;">.</span><span style="color: #000088;">$notifyemail</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// screen name exists - you can do something here if you want</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//$json_output = json_decode($json,true);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//print_r($json_output);</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>If you are running it from cron, add the sample entry:</p>
<div class="codecolorer-container text mac-classic" 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">0 * * * * /usr/bin/php /path/to/script.php</div></td></tr></tbody></table></div>
<p>The above would run the script every hour on the hour. </p>
<p>Of course you can easily modify this sample code if you are looking to do any kind of similar checking in your web app. If you find this kind of script useful, please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/find-out-if-a-twitter-username-exists-using-php-json/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using Google Analytics Or Other Javascript With Smarty Template Engine</title>
		<link>http://systembash.com/content/using-google-analytics-or-other-javascript-with-smarty-template-engine/</link>
		<comments>http://systembash.com/content/using-google-analytics-or-other-javascript-with-smarty-template-engine/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 20:45:53 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Webdesign]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[smarty]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=752</guid>
		<description><![CDATA[On a website I was working on recently I added the Google Analytics tracking code to the footer of a Smarty template, like this: footer.tpl: 1234567891011121314151617&#60;script type=&#34;text/javascript&#34;&#62; &#160; var _gaq = _gaq &#124;&#124; []; &#160; _gaq.push(['_setAccount', 'UA-XXXXX-XX']); &#160; _gaq.push(['_trackPageview']); &#160; (function() { &#160; &#160; var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>On a website I was working on recently I added the <a href="www.google.com/analytics/">Google Analytics</a> tracking code to the footer of a <a href="http://www.smarty.net/">Smarty template</a>, like this:</p>
<p>footer.tpl:</p>
<div class="codecolorer-container html4strict mac-classic" 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 /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
<br />
&nbsp; var _gaq = _gaq || [];<br />
&nbsp; _gaq.push(['_setAccount', 'UA-XXXXX-XX']);<br />
&nbsp; _gaq.push(['_trackPageview']);<br />
<br />
&nbsp; (function() {<br />
&nbsp; &nbsp; var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;<br />
&nbsp; &nbsp; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';<br />
&nbsp; &nbsp; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);<br />
&nbsp; })();<br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br />
<br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></div></td></tr></tbody></table></div>
<p>However, since the javascript used by Google Analytics includes { and } tags, also used by the Smarty template engine, it tries to interpret this code and depending on your settings will either fail silently or or with an error such as this:</p>
<pre>Smarty error: [in footer.tpl line 148]: syntax error: unrecognized tag 'var'</pre>
<p>The fix is simple. Enclose your Google Analytics code, or other javascript code, with {literal} and {/literal}. The <a href="http://www.smarty.net/manual/en/language.function.literal.php">literal tag</a> allows you to place code to be displayed, well, literally.</p>
<p>The final code will look something like this:</p>
<div class="codecolorer-container html4strict mac-classic" 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 />20<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">{literal}<br />
<br />
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span><br />
<br />
&nbsp; var _gaq = _gaq || [];<br />
&nbsp; _gaq.push(['_setAccount', 'UA-XXXXX-XX']);<br />
&nbsp; _gaq.push(['_trackPageview']);<br />
<br />
&nbsp; (function() {<br />
&nbsp; &nbsp; var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;<br />
&nbsp; &nbsp; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';<br />
&nbsp; &nbsp; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);<br />
&nbsp; })();<br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br />
<br />
{/literal}<br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></div></td></tr></tbody></table></div>
<p>Your website should now run properly with the Google Analytics code in place.</p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/using-google-analytics-or-other-javascript-with-smarty-template-engine/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 disk: enhanced
Database Caching 12/22 queries in 0.006 seconds using disk: basic

Served from: systembash.com @ 2012-05-23 23:15:06 -->
