<?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>Fri, 13 Jan 2012 03:18:25 +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>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>7</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 ? &#160; &#160; &#160; &#160;S &#160; &#160; &#160;0:00 &#160;\_ hald-runner 2481 ? &#160; &#160; &#160; &#160;S &#160; &#160; &#160;0:00 &#160; &#160; &#160;\_ hald-addon-acpi: listening on acpid socket /var/run/acpid.socket 2487 ? &#160; &#160; &#160; &#160;S &#160; &#160; &#160;0:00 &#160; &#160; &#160;\_ hald-addon-keyboard: listening on /dev/input/event0 2495 ? &#160; &#160; &#160; &#160;S &#160; &#160; 41:47 &#160; &#160; &#160;\_ hald-addon-storage: polling /dev/hdc If your system is static and the devices do not change, you can actually disable this service using a policy entry. Create a file in your policy directory, for example /etc/hal/fdi/policy/99-custom.fdi. Add the text: 123456789&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62;....]]></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 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. 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. Installing The Pascal Compiler on Ubuntu Installing Pascal in modern Ubuntu is a cinch. The Free Pascal Compiler, or fpc, is all that you need to....]]></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 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. 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. Originally I was going to try to write....]]></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 API to see if a screenname exists and if it doesn&#8217;t, shoot a short an email. I&#8217;ve been using changedetection 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. 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....]]></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; &#160; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; &#160; &#160; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); &#160; })(); &#60;/script&#62; &#60;/body&#62; &#60;/html&#62; 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: Smarty error: [in footer.tpl line 148]: syntax error: unrecognized tag 'var' The fix is simple. Enclose your Google Analytics code, or other javascript code, with {literal} and....]]></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>
		<item>
		<title>A phpBB 3 iPhone Style Theme With Option to Disable</title>
		<link>http://systembash.com/content/phpbb-3-iphone-style-theme-option-to-disable/</link>
		<comments>http://systembash.com/content/phpbb-3-iphone-style-theme-option-to-disable/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 12:34:37 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[phpbb]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=707</guid>
		<description><![CDATA[A forum that I am an adminstrator for has been clamoring for an iPhone theme (style) for a long time now. In the past, I hadn't seen any usable iPhone template for phpBB3, until now.

View this entire post to view my modifications to a theme switcher for mobile devices, so that the end user can disable a mobile theme for their login if they should choose to do so. ]]></description>
			<content:encoded><![CDATA[<p><img src="http://systembash.com/wp-content/uploads/2010/08/photo-200x300.png" alt="phpBB iPhone theme style" title="PHPBB iPhone Theme" width="200" height="300" class="alignright size-medium wp-image-711" />A forum that I am an adminstrator for has been clamoring for an iPhone theme (style) for a long time now. In the past, I hadn&#8217;t seen any usable iPhone template for phpBB3, until now.</p>
<p>The theme is hosted on Google code and is named <a href="http://code.google.com/p/phpbb-iphone-style/">phpbb-iphone-style</a>. It is downloadable <a href="http://code.google.com/p/phpbb-iphone-style/downloads/list">here</a> and was last updated June 18th, as of today.</p>
<p>The theme works wonderfully on the iPhone. However, the issue that I ran into is automatically displaying it for mobile browsers, such as the iPhone, Android and other platforms.</p>
<p>Fortunately there is a modification you can make to the phpbb code which is effectively a theme switcher for mobile browsers. The how to is located within the download file for the theme above.</p>
<h3>What if a user wants to turn off the mobile style?</h3>
<p>I modified the code to allow a user to set an option on their profile to permentently disable the theme when logged in on a mobile browser.</p>
<p>First, install the style as described above. As part of the switcher, you need to find out the theme ID. You can do so, after installing the style, by hovering over the &#8216;Detail&#8217; tab in the ACP (Administrator Control Panel) and looking for the &#8216;id&#8217; variable. In the example below it is &#8217;6&#8242;.</p>
<p>Once the theme is installed, move over to the &#8220;Users and Groups&#8221; tab, and then the &#8220;Custom Profile Fields&#8221; area. At the bottom of this page there is a box to add a new profile field. Type &#8216;disable_mobile&#8217; as the name, and Boolean (Yes/No) as the type and click add.</p>
<p>For the options, I selected:</p>
<ul>
<li>Publicly display profile field: No</li>
<li>Display in user control panel: Checked</li>
<li>Display on registration screen: Unchecked</li>
<li>Display on viewtopic screen: Unchecked</li>
<li>Required field: Unchecked</li>
<li>Hide profile field: Unchecked</li>
<li>Field name/title presented to the user: Disable Mobile Browser</li>
<li>Field description: When viewing on a mobile device (iPhone, Android, etc), clicking &#8216;yes&#8217; will disable the mobile browser.</li>
<li>Entries: First option: Yes, Second option: No</li>
</ul>
<p>On the second screen select the following items:</p>
<ul>
<li>Field type: Radio Buttons</li>
<li>Default value: no</li>
</ul>
<p>Save your custom profile field.</p>
<p>It will end up looking like this in the profile control panel of the end user:</p>
<p><center><img src="http://systembash.com/wp-content/uploads/2010/08/phpbb-style-disable.png" alt="phpbb iphone style disabler" title="phpbb-style-disable" width="500" height="107" class="size-full wp-image-710" /></center></p>
<p>Now the fun part, adding the code to your install to select which mobile browser to use automatically.</p>
<p>Back up, then open install dir/includes/session.php</p>
<p>Around line 1468 in the function setup</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>1468<br />1469<br />1470<br />1471<br />1472<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp; &nbsp; * Setup basic user-specific items (style, language, ...)<br />
&nbsp; &nbsp; &nbsp; &nbsp; */<br />
&nbsp; &nbsp; &nbsp; &nbsp; function setup($lang_set = false, $style = false)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {</div></td></tr></tbody></table></div>
<p>Replace</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 /></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;">global</span> <span style="color: #000088;">$db</span><span style="color: #339933;">,</span> <span style="color: #000088;">$template</span><span style="color: #339933;">,</span> <span style="color: #000088;">$config</span><span style="color: #339933;">,</span> <span style="color: #000088;">$auth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$phpEx</span><span style="color: #339933;">,</span> <span style="color: #000088;">$phpbb_root_path</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cache</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>with</p>
<div class="codecolorer-container php 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 /></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;">global</span> <span style="color: #000088;">$db</span><span style="color: #339933;">,</span> <span style="color: #000088;">$template</span><span style="color: #339933;">,</span> <span style="color: #000088;">$config</span><span style="color: #339933;">,</span> <span style="color: #000088;">$auth</span><span style="color: #339933;">,</span> <span style="color: #000088;">$phpEx</span><span style="color: #339933;">,</span> <span style="color: #000088;">$phpbb_root_path</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cache</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">;</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">//-----Begin phone detection &amp; redirection code-----</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_profile_fields</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'user_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$user_fields</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">profile_fields</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// if (!($user_fields['pf_disable_mobile'] == 1)) { &nbsp;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Thanks to Chris Dembek for this code fix</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pf_disable_mobile'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_fields</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'pf_disable_mobile'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//id of the iphone/mobile theme - SELECT THIS FROM YOUR STYLES </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$mobilestyleid</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Fetch the users browser</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$user_browser</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">browser</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//List of mobile user-agent keywords</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$browsers_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'240x320'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'320x240'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'blackberry'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'iemobile'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'minimobile'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mobile'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'opera mini'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'pda'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'phone'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'pocket'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'psp'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'symbian'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'t-shark'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wireless'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Check for the user-agent in the list of mobile user-agents</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$browsers_array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ua_match</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_browser</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ua_match</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp;<span style="color: #666666; font-style: italic;">//a match</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$style</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mobilestyleid</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_mobile'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//-----End phone detection/redirection code-----</span></div></td></tr></tbody></table></div>
<p><strong>Make sure to replace $mobilestyleid = 6 with your style id number!</strong></p>
<p>Save your file. Test out the modifications on your phone, you should be presented with the mobile version on reload (make sure to purge any cache if you don&#8217;t see it right away). </p>
<p>Finally go into your profile and select the &#8216;disable mobile browser&#8217; option and make sure it reverts back to your regular default theme. </p>
<p>Let me know if you have any problems implementing this but it has worked great for this phpbb forum!</p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/phpbb-3-iphone-style-theme-option-to-disable/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Another Bash One Liner To Delete Old Directories</title>
		<link>http://systembash.com/content/another-bash-one-liner-to-delete-old-directories/</link>
		<comments>http://systembash.com/content/another-bash-one-liner-to-delete-old-directories/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 22:05:58 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[oneliner]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=685</guid>
		<description><![CDATA[We received a tip from blog readers Christian and Michael for alternatives to the command to delete all directories older than a certain period of time. These both work in bash and can be used in scripts to clean up old backup directories or any situation where you need to delete old directories from the command line. From Christian: find /home/backup/ -maxdepth 1 -type d -mtime +7 -exec rm -r {} \; From Michael: find /home/backup/ -maxdepth 1 -type d -mtime +7 -exec echo “Removing Directory =&#62; {}” \; -exec rm -rf “{}” \; The first one works quietly, while the second one will display what is being deleted. These are probably faster than putting it into a for loop, so feel free to use whatever works best in your particular situation!]]></description>
			<content:encoded><![CDATA[<p>We received a tip from blog readers Christian and Michael for alternatives to the <a href="http://systembash.com/content/delete-directories-older-than-week/">command to delete all directories older than a certain period of time</a>. These both work in bash and can be used in scripts to clean up old backup directories or any situation where you need to delete old directories from the command line.</p>
<p>From Christian:</p>
<pre>find /home/backup/ -maxdepth 1 -type d -mtime +7 -exec rm -r {} \;</pre>
<p>From Michael:</p>
<pre>find /home/backup/ -maxdepth 1 -type d -mtime +7 -exec echo “Removing Directory =&gt; {}” \; -exec rm -rf “{}” \;</pre>
<p>The first one works quietly, while the second one will display what is being deleted. These are probably faster than putting it into a for loop, so feel free to use whatever works best in your particular situation!</p>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/another-bash-one-liner-to-delete-old-directories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One Line Linux Command to Print Out Directory Tree Listing</title>
		<link>http://systembash.com/content/one-line-linux-command-to-print-out-directory-tree-listing/</link>
		<comments>http://systembash.com/content/one-line-linux-command-to-print-out-directory-tree-listing/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 21:41:55 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://systembash.com/?p=650</guid>
		<description><![CDATA[My professor sent us this little one liner (ok, I had to format it to 2 lines to fit in this blog. You know what I mean) which prints out the current directory tree: ls -R &#124; grep ":$" &#124; sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' \ -e 's/^/ /' -e 's/-/&#124;/' What&#8217;s going on here? 1ls -R &#8211; list files and directories recursively 1grep &#34;:$&#34; &#8211; find lines with : at the end (so only the directories) 1sed -e &#8211; evaluate expressions on the lines 1s/:$// &#8211; remove &#8216;:&#8217; at the end of the line 1s/[^-][^\/]*\//--/g &#8211; replaces text between / / lines (parent directories) with &#8212; , globally on each line 1s/^/ / &#8211; add space at the beginning of the lines 1s/-/&#124;/ &#8211; replace first &#8211; of the line with &#124; I reduced this using the following command. The most notable difference is that I use find instead....]]></description>
			<content:encoded><![CDATA[<p>My professor sent us this little one liner (ok, I had to format it to 2 lines to fit in this blog. You know what I mean) which prints out the current directory tree:</p>
<pre>ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' \
-e 's/^/ /' -e 's/-/|/'</pre>
<p>What&#8217;s going on here?<br />
<span id="more-650"></span></p>
<ul>
<li>
<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">ls -R</div></td></tr></tbody></table></div>
<p>&#8211; list files and directories recursively</li>
<li>
<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">grep &quot;:$&quot;</div></td></tr></tbody></table></div>
<p>&#8211; find lines with : at the end (so only the directories)</li>
<li>
<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">sed -e</div></td></tr></tbody></table></div>
<p>&#8211;  evaluate expressions on the lines</li>
<li>
<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">s/:$//</div></td></tr></tbody></table></div>
<p>&#8211; remove &#8216;:&#8217; at the end of the line</li>
<li>
<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">s/[^-][^\/]*\//--/g</div></td></tr></tbody></table></div>
<p>&#8211; replaces text between / / lines (parent directories) with &#8212; , globally on each line</li>
<li>
<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">s/^/ /</div></td></tr></tbody></table></div>
<p>&#8211; add space at the beginning of the lines</li>
<li>
<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">s/-/|/</div></td></tr></tbody></table></div>
<p>&#8211; replace first &#8211; of the line with |</li>
</ul>
<p>I reduced this using the following command. The most notable difference is that I use find instead of ls, which results in also viewing .hidden directories. I&#8217;m not sure which command is faster.</p>
<pre>find ./ -type d | sed -e 's/[^-][^\/]*\//--/g;s/--/ |-/'</pre>
<p>Both commands result in a formatted directory listing, demonstrated below:</p>
<pre>|-sitetransfer
 |---redacteddomain.com
 |-----cache
 |-----templates
 |-------skidoo_too
 |---------images
 |-----------_vti_cnf
 |---------css
 |-----------_vti_cnf
 |---------js
 |-----------scriptaculous
 |-------------src
 |-------------lib
 |---------admin_templates</pre>
]]></content:encoded>
			<wfw:commentRss>http://systembash.com/content/one-line-linux-command-to-print-out-directory-tree-listing/feed/</wfw:commentRss>
		<slash:comments>5</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 using disk: basic

Served from: systembash.com @ 2012-02-08 15:20:52 -->
