<?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>Aaron Toponce &#187; Scripting</title> <atom:link href="http://pthree.org/category/scripting/feed/" rel="self" type="application/rss+xml" /><link>http://pthree.org</link> <description>Linux.  GNU.  Freedom.</description> <lastBuildDate>Wed, 01 Sep 2010 22:04:20 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1-alpha</generator> <item><title>My ZSH, Irssi and Screen Themes On White And Black Backgrounds</title><link>http://pthree.org/2010/04/29/my-zsh-irssi-and-screen-themes-on-white-and-black-backgrounds/</link> <comments>http://pthree.org/2010/04/29/my-zsh-irssi-and-screen-themes-on-white-and-black-backgrounds/#comments</comments> <pubDate>Fri, 30 Apr 2010 06:43:38 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[Scripting]]></category> <category><![CDATA[irssi]]></category><guid
isPermaLink="false">http://pthree.org/?p=1359</guid> <description><![CDATA[Now that school is out for the summer, I have a bit of time to work on some of the themes I&#8217;ve created for my ZSH prompt, Irssi and GNU Screen. The first focus of mine was to get all themes working well with both white text on black backgrounds, and black text on white [...]]]></description> <content:encoded><![CDATA[<p>Now that school is out for the summer, I have a bit of time to work on some of the themes I&#8217;ve created for my ZSH prompt, Irssi and GNU Screen. The first focus of mine was to get all themes working well with both white text on black backgrounds, and black text on white backgrounds. I&#8217;ve been leaning more and more to black text on white background colors for my default terminals, so I wanted to make sure that everything I was using day-to-day looked good with that setup.</p><p>First, my ZSH prompt was <a
href="http://pthree.org/2009/10/14/more-zsh-prompt-love/">already developed</a> from the outset with that in mind. So, no additional hacking has been needed on that. There are some elements that I&#8217;m not too terribly excited about. I don&#8217;t care for the dark blue directories on a black background, and I don&#8217;t care for the yellow character devices on a white background. Using the <a
href="http://tango.freedesktop.org/Tango_Desktop_Project">Tango scheme</a> for gnome-terminal makes both of those scenarios much more tolerable. However, I do have additional items that I want to put in my prompt, but that will be for a later post. Also, my GNU Screen hardstatus line also needed to be compatible. This wasn&#8217;t that big of a deal, as I only needed to apply some colors to a few elements. Hhere&#8217;s a couple screenshots showing both black and white backgrounds, and how the ZSH prompt inside looks in each. Note the GNU Screen hardstatus line is at the bottom of the terminal.</p><table
style="width:auto;"><tr><td><a
href="http://picasaweb.google.com/lh/photo/VEs4lOWonaHjJUfZhvVAuA?feat=embedwebsite"><img
src="http://lh6.ggpht.com/_UjZEx7iINYc/S9pzPJlvNQI/AAAAAAAAAx4/vBb1Xij848s/s144/zsh-screen-white.png" /></a></td></tr><tr><td
style="font-family:arial,sans-serif; font-size:11px; text-align:right">From <a
href="http://picasaweb.google.com/aaron.toponce/DesktopScreenshots?feat=embedwebsite">Desktop Screenshots</a></td></tr></table><table
style="width:auto;"><tr><td><a
href="http://picasaweb.google.com/lh/photo/L0SeomtjbteBgH95hyKdCA?feat=embedwebsite"><img
src="http://lh3.ggpht.com/_UjZEx7iINYc/S9pzPPgsL8I/AAAAAAAAAx0/CjszuCg_Hyw/s144/zsh-screen-black.png" /></a></td></tr><tr><td
style="font-family:arial,sans-serif; font-size:11px; text-align:right">From <a
href="http://picasaweb.google.com/aaron.toponce/DesktopScreenshots?feat=embedwebsite">Desktop Screenshots</a></td></tr></table><p>Second, my Irssi theme also needed to work well with both. As I&#8217;ve already blogged before, I was really, <i>really</i> <a
href="http://pthree.org/2010/01/12/more-88-madcows/">impressed with the madcows theme</a>. However, I didn&#8217;t care for a few elements, so I started hacking it, making my own changes. I&#8217;ve tried keeping the true nature of the theme, while still adding my own style. The theme was already largely compatible with my ZSH prompt colors, it just needed some adjustments here and there, before I was totally satisfied. Further, it looked like crap using a white background, so this needed some hacking as well. I think I&#8217;m overall happy with the result, although I&#8217;m sure I&#8217;ve missed many things (like DCC, or CTCP), so there&#8217;s likely much more hacking to go before it&#8217;s perfect. However, for the general day-to-day chat, it&#8217;s 95% there. Screenshots for both backgrounds below:</p><table
style="width:auto;"><tr><td><a
href="http://picasaweb.google.com/lh/photo/0DvCb_vsNGWKN3j6vi7uNg?feat=embedwebsite"><img
src="http://lh5.ggpht.com/_UjZEx7iINYc/S9pzOj281fI/AAAAAAAAAxw/YL-NyubDrb8/s144/irssi-white.png" /></a></td></tr><tr><td
style="font-family:arial,sans-serif; font-size:11px; text-align:right">From <a
href="http://picasaweb.google.com/aaron.toponce/DesktopScreenshots?feat=embedwebsite">Desktop Screenshots</a></td></tr></table><table
style="width:auto;"><tr><td><a
href="http://picasaweb.google.com/lh/photo/Hdxl0nvnQ3wHCfRKiyQWwQ?feat=embedwebsite"><img
src="http://lh4.ggpht.com/_UjZEx7iINYc/S9pzOaOQ0uI/AAAAAAAAAxs/iC70wR8vCcI/s144/irssi-black.png" /></a></td></tr><tr><td
style="font-family:arial,sans-serif; font-size:11px; text-align:right">From <a
href="http://picasaweb.google.com/aaron.toponce/DesktopScreenshots?feat=embedwebsite">Desktop Screenshots</a></td></tr></table><p>In a nutshell, the themes are compatible with xterm-color support on most terminals. Mainly, I&#8217;m using bold and normal weights on red, green, yellow, black, white and blue. Anything else takes the default color of the terminal itself, whether it be the foreground text or the background. So, as long as your TERM variable is set to &#8220;xterm-color&#8221; or something better, you should be okay.</p><p>This post wouldn&#8217;t be complete without the source for you to try it out. <a
href="http://pthree.org/wp-content/uploads/2010/04/all-themes.tar.gz">Here&#8217;s a compressed tarball</a> for giving it a shot, and reporting anything you find in the comments, if you like.</p><p>Cheers!</p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2010/04/29/my-zsh-irssi-and-screen-themes-on-white-and-black-backgrounds/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Add Colors To Your ZSH Scripts</title><link>http://pthree.org/2009/12/18/add-colors-to-your-zsh-scripts/</link> <comments>http://pthree.org/2009/12/18/add-colors-to-your-zsh-scripts/#comments</comments> <pubDate>Fri, 18 Dec 2009 22:58:29 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Scripting]]></category><guid
isPermaLink="false">http://pthree.org/?p=1201</guid> <description><![CDATA[I was writing some scripts this morning to help me keep the Unix and Linux server I administer at work up to date with their NTP time synchronization. As I was going along, I thought to myself, &#8220;I&#8217;d like to see some color in the output.&#8221; Thankfully, I already had the code in my ZSH [...]]]></description> <content:encoded><![CDATA[<p>I was writing some scripts this morning to help me keep the Unix and Linux server I administer at work up to date with their NTP time synchronization. As I was going along, I thought to myself, &#8220;I&#8217;d like to see some color in the output.&#8221; Thankfully, <a
href="http://pthree.org/2009/10/14/more-zsh-prompt-love/">I already had the code in my ZSH prompt</a>. All I needed to do was remove some sigils, and I was up and running. If you want to add color to the output of your ZSH scripts, here&#8217;s what you need to add:</p><div
class="codecolorer-container bash twitlight" 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="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">autoload colors<br
/> <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span><span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$terminfo</span>[colors]&quot;</span> <span
style="color: #660033;">-gt</span> <span
style="color: #000000;">8</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span><span
style="color: #7a0874; font-weight: bold;">&#93;</span>; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; colors<br
/> <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <span
style="color: #000000; font-weight: bold;">for</span> COLOR <span
style="color: #000000; font-weight: bold;">in</span> RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; <span
style="color: #000000; font-weight: bold;">do</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">eval</span> <span
style="color: #007800;">$COLOR</span>=<span
style="color: #ff0000;">'$fg_no_bold[${(L)COLOR}]'</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">eval</span> BOLD_<span
style="color: #007800;">$COLOR</span>=<span
style="color: #ff0000;">'$fg_bold[${(L)COLOR}]'</span><br
/> <span
style="color: #000000; font-weight: bold;">done</span><br
/> <span
style="color: #7a0874; font-weight: bold;">eval</span> <span
style="color: #007800;">RESET</span>=<span
style="color: #ff0000;">'$reset_color'</span></div></td></tr></tbody></table></div><p>You now have the following variables available in the shell script namepace: RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, BLACK, WHITE, BOLD_RED, BOLD_GREEN, BOLD_YELLOW, BOLD_BLUE, BOLD_MAGENTA, BOLD_CYAN, BOLD_BLACK, BOLD_WHITE, RESET. Using these variables, you can manipulate the output from &#8220;echo&#8221; and &#8220;printf&#8221; for your script. For example, <a
href="http://picasaweb.google.com/lh/photo/5dfKS0uddBu57qpaAhIhtg?feat=directlink">here&#8217;s a screenshot using &#8220;echo&#8221; to print red, green and blue text to the screen</a>. Notice that I&#8217;m using the &#8220;RESET&#8221; variable after the blue text to reset my prompt text back to normal. This may or may not be necessary, depending on how you configured your prompt, but it&#8217;s not a bad habit to get into.</p><p>Thought this might be helpful to the larger scripting community or for those sysadmins, such as myself, who would like a little variety added to their script output.</p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2009/12/18/add-colors-to-your-zsh-scripts/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>More ZSH Prompt Love</title><link>http://pthree.org/2009/10/14/more-zsh-prompt-love/</link> <comments>http://pthree.org/2009/10/14/more-zsh-prompt-love/#comments</comments> <pubDate>Wed, 14 Oct 2009 14:51:24 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Personal]]></category> <category><![CDATA[Scripting]]></category><guid
isPermaLink="false">http://pthree.org/?p=1148</guid> <description><![CDATA[Ever since discovering ZSH 3 years ago, I&#8217;ve been addicted, but it wasn&#8217;t until a good 2 years into using the prompt on a daily basis that I decided to do some radical work with my prompt. I&#8217;ve blogged about this before a couple times, making improvements along the way: post 0, post 1, post [...]]]></description> <content:encoded><![CDATA[<p>Ever since discovering ZSH 3 years ago, I&#8217;ve been addicted, but it wasn&#8217;t until a good 2 years into using the prompt on a daily basis that I decided to do some radical work with my prompt. I&#8217;ve blogged about this before a couple times, making improvements along the way: <a
href="http://pthree.org/2008/01/31/my-zsh-prompt/">post 0</a>, <a
href="http://pthree.org/2008/03/29/my-zsh-prompt-improved/">post 1</a>, <a
href="http://pthree.org/2008/11/23/727/">post 2</a>, <a
href="http://pthree.org/2009/03/28/add-vim-editing-mode-to-your-zsh-prompt/">post 3</a>. Check out those posts if you&#8217;re interested in what I&#8217;ve done to the prompt, and extra screenshots.</p><p>At the Utah Open Source Conference, I gave a BOF on Unix shells. The turnout was good, and we had a great discussion. I presented on my default prompt for ZSH, showing all the hidden features of the prompt. However, I had forgotten that I had removed battery status from my prompt, because I was depending on APM, which is no longer compiled in the kernel. A couple people have asked me since then why I&#8217;m depending on APM and not ACPI. I don&#8217;t have an answer, other than that was just what I coded. So, last night, I put up an ACPI implementation, and it works great. As with the APM implementation, if the battery percentage is less than 15%, the percentage display is red. If it&#8217;s less than 50% but greater than 14%, it&#8217;s yellow, and if it&#8217;s less than 100% but greater than 49%, it&#8217;s blue. If it&#8217;s 100%, or the tool &#8220;acpi&#8221; is not installed, then it doesn&#8217;t show up. Here&#8217;s a screenshot below:</p><p><img
src="http://pthree.org/wp-content/uploads/2009/10/battery-34percent.png" alt="Battery Percentage in ZSH prompt" title="Battery Percentage in ZSH prompt" width="570" height="388" class="aligncenter size-full wp-image-1150" /></p><p>While hanging out in our local LUG channel for the Ogden Area Linux Users Group, I got talking with Seth about prompts. He decided to change his, including adding the dog from Nethack randomly &#8220;moving&#8221; in the prompt. He also mentioned changing the color of the path if the present working directory was not writable. I really liked this idea, and decided to implement it in my prompt. Here&#8217;s a screenshot of that in action:</p><p><img
src="http://pthree.org/wp-content/uploads/2009/10/path-color-change.png" alt="Path color change in ZSH prompt" title="Path color change in ZSH prompt" width="570" height="388" class="aligncenter size-full wp-image-1151" /></p><p>I change the path color to yellow if the present working directory is not writable, as it&#8217;s noticeable enough to catch your attention, but subtle enough to not get in the way, and be distracting.</p><p>As usual, if you want the source, <a
href="http://pthree.org/wp-content/uploads/2009/10/zsh-prompt.txt">here it is</a>. Yes, it&#8217;s public domain, as mentioned in the code, so have at it.</p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2009/10/14/more-zsh-prompt-love/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Password Policies Suck</title><link>http://pthree.org/2009/05/28/password-policies-suck/</link> <comments>http://pthree.org/2009/05/28/password-policies-suck/#comments</comments> <pubDate>Thu, 28 May 2009 22:06:40 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[Scripting]]></category><guid
isPermaLink="false">http://pthree.org/?p=1062</guid> <description><![CDATA[I&#8217;ve been getting a flurry of emails at work, reminding me that my passwords are about to expire on several Unix and Linux machines in our production datacenter. They have a policy in place, where the password much be changed every 90 days, and I have to keep my current password for at least 7 [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve been getting a flurry of emails at work, reminding me that my passwords are about to expire on several Unix and Linux machines in our production datacenter. They have a policy in place, where the password much be changed every 90 days, and I have to keep my current password for at least 7 before changing it, and I can&#8217;t use any password that has been used previously, let alone, the insane requirements for the password. So, rather than fight it, I thought I would make this easy on myself.</p><p>First, I&#8217;m a big fan of SSH key authentication. Because I&#8217;m allowed to use SSH authentication, I have my public SSH key on all the servers in the datacenter. When my password is about to expire, I get an email notice once per day two weeks in advance. I can use this email as an opportunity to execute a script that will change all the passwords on all the servers for me. In the script, I&#8217;ll have it grab some data from /dev/urandom, and create a sha1sum of the input. An encrypted version of the hash will then be saved locally to disk, which will be encrypted with my GnuPG key, and emailed to myself, should I need the password for something other than SSH. Lastly, just so the password can&#8217;t be compromised, only the encrypted versions of the password remain on disk. The hashes themselves are shell variables that are cleared when the script exits. Further, I&#8217;ve changed the permissions on my home directory, where my SSH keys and GnuPG keys exist, such that everything sensitive is only accessible to myself. I realize that convenience comes at the sacrifice of a bit of security. My laptop is running full disk encryption, and my password to guard my account is strong. I am the only one on my machine, and I expect it to stay that way. As such, I&#8217;m not worried about anything getting compromised.</p><p>All of this is stored in a simple shell script, shown below. You will need the &#8220;expect&#8221; and &#8220;sha1sum&#8221; packages installed on your system before executing this script. You will need a GnuPG key pair generated for encrypting and decrypting data. You&#8217;ll need SSH keys created and distributed to each server beforehand. You should probably have your SSH keys added to your SSH agent, as well as your GnuPG key added to a GPG agent before executing the script, to save you some serious typing. I won&#8217;t cover that here, but Seahorse is a great utility for managing GPG and SSH keys. Of course, your SSH keys and GPG keys should be passphrase protected.</p><div
class="codecolorer-container bash twitlight" 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
/></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: #666666; font-style: italic;"># License: public domain</span><br
/> <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span><span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #660033;">-f</span> newpass.gpg <span
style="color: #7a0874; font-weight: bold;">&#93;</span><span
style="color: #7a0874; font-weight: bold;">&#93;</span>; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">mv</span> <span
style="color: #660033;">-f</span> newpass.gpg oldpass.gpg<br
/> &nbsp; &nbsp; <span
style="color: #007800;">OLDPASSWD</span>=<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$(gpg -d oldpass.gpg)</span>&quot;</span><br
/> <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Change &quot;Your Name&quot; to fit the user ID that matches in your GPG key</span><br
/> <span
style="color: #c20cb9; font-weight: bold;">dd</span> <span
style="color: #007800;">if</span>=<span
style="color: #000000; font-weight: bold;">/</span>dev<span
style="color: #000000; font-weight: bold;">/</span>urandom <span
style="color: #007800;">count</span>=<span
style="color: #000000;">100</span> <span
style="color: #000000;">2</span><span
style="color: #000000; font-weight: bold;">&gt;</span> <span
style="color: #000000; font-weight: bold;">/</span>dev<span
style="color: #000000; font-weight: bold;">/</span>null <span
style="color: #000000; font-weight: bold;">|</span> sha1sum <span
style="color: #660033;">-b</span> - <span
style="color: #000000; font-weight: bold;">|</span> \<br
/> gpg <span
style="color: #660033;">-ar</span> <span
style="color: #ff0000;">&quot;Your Name&quot;</span> <span
style="color: #660033;">-e</span> - <span
style="color: #000000; font-weight: bold;">&gt;</span> newpass.gpg<br
/> <span
style="color: #666666; font-style: italic;"># Change &quot;username@domain.tld&quot; to match the email you wish to send this to</span><br
/> <span
style="color: #c20cb9; font-weight: bold;">cat</span> newpass.gpg <span
style="color: #000000; font-weight: bold;">|</span> mail <span
style="color: #660033;">-s</span> <span
style="color: #ff0000;">&quot;Password for servers&quot;</span> username<span
style="color: #000000; font-weight: bold;">@</span>domain.tld<br
/> <br
/> <span
style="color: #007800;">NEWPASSWD</span>=<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$(gpg -d newpass.gpg)</span>&quot;</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Change &quot;server1 server2 sever3&quot; to match the hostnames of the servers you'll loop over</span><br
/> <span
style="color: #666666; font-style: italic;"># Change &quot;domain.tld&quot; to match the FQDN for your servers</span><br
/> <span
style="color: #000000; font-weight: bold;">for</span> host <span
style="color: #000000; font-weight: bold;">in</span> server1 server2 server3; <span
style="color: #000000; font-weight: bold;">do</span><br
/> &nbsp; &nbsp; <span
style="color: #007800;">EXPECT</span>=$<span
style="color: #7a0874; font-weight: bold;">&#40;</span>expect <span
style="color: #660033;">-c</span> <span
style="color: #ff0000;">&quot;<br
/> &nbsp; &nbsp; &nbsp; &nbsp; spawn ssh <span
style="color: #007800;">$host</span>.domain.tld<br
/> &nbsp; &nbsp; &nbsp; &nbsp; send <span
style="color: #000099; font-weight: bold;">\&quot;</span>passwd<span
style="color: #000099; font-weight: bold;">\r</span><span
style="color: #000099; font-weight: bold;">\&quot;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; expect <span
style="color: #000099; font-weight: bold;">\&quot;</span>(current) UNIX password: <span
style="color: #000099; font-weight: bold;">\&quot;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; send <span
style="color: #000099; font-weight: bold;">\&quot;</span><span
style="color: #007800;">$OLDPASSWD</span><span
style="color: #000099; font-weight: bold;">\r</span><span
style="color: #000099; font-weight: bold;">\&quot;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; expect <span
style="color: #000099; font-weight: bold;">\&quot;</span>New UNIX password: <span
style="color: #000099; font-weight: bold;">\&quot;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; send <span
style="color: #000099; font-weight: bold;">\&quot;</span><span
style="color: #007800;">$NEWPASSWD</span><span
style="color: #000099; font-weight: bold;">\r</span><span
style="color: #000099; font-weight: bold;">\&quot;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; expect <span
style="color: #000099; font-weight: bold;">\&quot;</span>Retype new password: <span
style="color: #000099; font-weight: bold;">\&quot;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; send <span
style="color: #000099; font-weight: bold;">\&quot;</span><span
style="color: #007800;">$NEWPASSWD</span><span
style="color: #000099; font-weight: bold;">\r</span><span
style="color: #000099; font-weight: bold;">\&quot;</span><br
/> &nbsp; &nbsp; &quot;</span><span
style="color: #7a0874; font-weight: bold;">&#41;</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #007800;">$EXPECT</span><br
/> <span
style="color: #000000; font-weight: bold;">done</span></div></td></tr></tbody></table></div><p>Initially, when I started writing this script, I wanted it to run in cron locally on my laptop. As I began building the script, I realized this wasn&#8217;t a secure move, for a couple of reasons. First, as already mentioned, I&#8217;m using SSH authentication using public key cryptography. All of my SSH keys are passphrase protected. I didn&#8217;t want to store the passphrase in the script, so I could automate the process, and I didn&#8217;t want to remove the passphrase or generate new keys that didn&#8217;t have a passphrase. Further, wanting to encrypt the data, and send it to myself via email required that I store my GnuPG passphrase on disk as well. I didn&#8217;t like this idea either, as I&#8217;m already storing the new and old encrypted passwords on disk from the script, and that&#8217;s enough. No need to compromise security any further. So, I&#8217;ll run this script by hand.</p><p>However, we have a problem. You will be typing passphrases galore in this script if you have a decent number of hosts to loop through. So, as mentioned, it would probably be best to take advantage of an SSH and GPG agent to cache your passphrases to ease the pain before executing the script.</p><p>Looking over the script a bit. First thing to note, is it is sending the same password to every server. You might not want this. If so, feel free to modify the script to fit your needs. Second, the sha1sum hash is never stored on disk. Rather, it&#8217;s just stored in variables OLDPASS and NEWPASS. The idea between the old passwords and the new passwords, is so we can provide the current password when updating, as well as the old.</p><p>We&#8217;re pulling from /dev/urandom as a source for semi-random data. Yes, you can pull from /dev/random if it makes you sleep better at night. Also, we&#8217;re not pulling a lot of data, because ultimately, the SHA1 hash will be strong enough as it is. You&#8217;ll notice too that because we&#8217;re using STDIN for our data source, the hash contains a space, asterisk and hyphen following the hash, and we&#8217;re keeping it. I figured no reason to remove it, as spaces, asterisks and hyphens are valid UNIX password characters. If your company has a more draconian password policy than mine does, requiring specifically more than say 3 or 5 non-alphanumeric characters, then just append those to the end of hash before encrypting to disk. Maybe something like the string &#8220;!@#$%&#8221;.</p><p>Lastly, we&#8217;re emailing the encrypted password to ourselves, so no worries about compromising there, plus that gives us an extra backup in case we lose our disk that is storing the encrypted passwords. This also gives flexibility to where we can retrieve the password, provided we have access to the Internet and our GPG keys. Then we&#8217;re using &#8220;expect&#8221; to send the passwd command to the server and send our old and new passwords as prompted for each server. You might need to change the expected prompt depending on your GNU/Linux or Unix derivative (&#8220;New RedHat password: &#8221; for example).</p><p>That&#8217;s it! Simple enough. If you have any questions, or improvements, please post them in the comments. Thanks!</p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2009/05/28/password-policies-suck/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Add Vim Editing Mode To Your ZSH Prompt</title><link>http://pthree.org/2009/03/28/add-vim-editing-mode-to-your-zsh-prompt/</link> <comments>http://pthree.org/2009/03/28/add-vim-editing-mode-to-your-zsh-prompt/#comments</comments> <pubDate>Sun, 29 Mar 2009 05:11:27 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Scripting]]></category><guid
isPermaLink="false">http://pthree.org/?p=1008</guid> <description><![CDATA[I&#8217;ve decided to go back to vi mode with my shell. Of course, by default, BASH, ZSH and others use emacs mode for the keyboard bindings. This is fine for the generic case, but if I&#8217;m using Vim for my default editor, it makes sense to use the Vi keyboard bindings in my shell as [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve decided to go back to vi mode with my shell. Of course, by default, BASH, ZSH and others use emacs mode for the keyboard bindings. This is fine for the generic case, but if I&#8217;m using Vim for my default editor, it makes sense to use the Vi keyboard bindings in my shell as well. However, I have an extremely dynamic shell, so if I&#8217;m going to start using Vi mode, I better have my shell tell me when I&#8217;m in command mode or insert mode.</p><p>On Vim, the default mode is command mode, and when you go into a different mode, you&#8217;re notified, such as going into insert mode. However, with the ZSH, when you start up your prompt, you are in insert mode by default, and you must press your ESC key to go into command mode. So, seeing as though insert mode is default, rather than be notified constantly that I&#8217;m in insert mode, I&#8217;d rather be notified when I enter command mode. Also, I wanted a way to do this dynamically, so when I pressed my ESC key, I got an immediate visual that I entered command mode. The same event should happen when I go back into insert mode- my visual should disappear.</p><p>I wasn&#8217;t sure how to approach this, so after a bit of Googling, I discovered that I need to write a ZSH widget. I&#8217;ve never written a ZSH widget before. In fact, to be honest, I didn&#8217;t even know they existed. However, I was curious, and learned that I need to use the &#8216;zle -N&#8217; command on a widget. By doing so, this widget will operate on the shell in real time, without waiting for the enter key to be pressed. This is exactly what I&#8217;m after. So, the only thing left to do was write a bit of logic handling when I&#8217;m in command mode, and when I&#8217;m not. Here&#8217;s the relevant bit of code:</p><div
class="codecolorer-container bash twitlight" 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="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #666666; font-style: italic;"># If I am using vi keys, I want to know what mode I'm currently using.</span><br
/> <span
style="color: #666666; font-style: italic;"># zle-keymap-select is executed every time KEYMAP changes.</span><br
/> <span
style="color: #666666; font-style: italic;"># From http://zshwiki.org/home/examples/zlewidgets</span><br
/> <span
style="color: #000000; font-weight: bold;">function</span> zle-keymap-select <span
style="color: #7a0874; font-weight: bold;">&#123;</span><br
/> &nbsp; &nbsp; <span
style="color: #007800;">VIMODE</span>=<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">${${KEYMAP/vicmd/ M:command}</span>/(main|viins)/}&quot;</span><br
/> &nbsp; &nbsp; zle reset-prompt<br
/> <span
style="color: #7a0874; font-weight: bold;">&#125;</span><br
/> <br
/> zle <span
style="color: #660033;">-N</span> zle-keymap-select</div></td></tr></tbody></table></div><p>Fairly straight forward I think. If the KEYMAP variable is set to &#8220;vicmd&#8221;, then we&#8217;re in command mode with vi on the shell, and we can set our VIMODE variable to &#8221; M:command&#8221; (to match the rest of my prompt). If the KEYMAP variable is set to &#8220;main&#8221; or &#8220;viins&#8221;, then we can unset VIMODE. The way we do this is using inline ZSH substitution using ${VARIABLE/PATTERN} syntax. This says to search for our pattern anywhere within our variable. Check out the zshexpn(1) man page for more info and examples. Notice I&#8217;m running &#8216;zle reset-prompt&#8217;. Because this is a widget, I can take advantage of redrawing the prompt whenever I need. Now, the only thing left to do is put the $VIMODE variable in my prompt, and I&#8217;ll have a dynamic visual of when I enter command mode and when I leave it. Here&#8217;s some screenshot candy:</p><p><img
src="http://pthree.org/wp-content/uploads/2009/03/zsh-insert-mode.png" alt="Screenshot showing a ZSH prompt without the command mode visual." />&nbsp;<img
src="http://pthree.org/wp-content/uploads/2009/03/zsh-command-mode.png" alt="Screenshot showing a ZSH prompt with the command mode visual" /></p><p>For the need-to-have-it readers, <a
href="http://pthree.org/wp-content/uploads/2009/03/zsh_prompt">here&#8217;s the full source to my prompt</a>. Just source the file in your .zshrc, and make sure that your TERM variable is set appropriately to handle terminal colors.</p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2009/03/28/add-vim-editing-mode-to-your-zsh-prompt/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>DASH on Ubuntu</title><link>http://pthree.org/2008/06/27/dash-on-ubuntu/</link> <comments>http://pthree.org/2008/06/27/dash-on-ubuntu/#comments</comments> <pubDate>Fri, 27 Jun 2008 22:55:06 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Scripting]]></category> <category><![CDATA[Ubuntu]]></category><guid
isPermaLink="false">http://pthree.org/?p=614</guid> <description><![CDATA[A couple recent posts have started on the Utah Open Source Planet regarding popd and pushd not being available on a default Ubuntu install. As discovered, popd and pushd are shell built-ins for the BASH shell, and not provided by the Debian Almquist Shell (DASH). Why has Ubuntu made the change from BASH to DASH [...]]]></description> <content:encoded><![CDATA[<p>A couple recent posts have started on the <a
href="http://openclue.org">Utah Open Source Planet</a> regarding popd and pushd not being available on a default Ubuntu install.  As discovered, popd and pushd are shell built-ins for the BASH shell, and not provided by the Debian Almquist Shell (DASH).  Why has Ubuntu made the change from BASH to DASH as the default shell?  Well, there some reasons for it, as identified by the <a
href="https://wiki.ubuntu.com/DashAsBinSh">Ubuntu Wiki</a>.</p><p>BASH is full-featured bloat.  Yes, bloat.  If System V Init scripts are relying on BASH to start their service, your boot process will be slower.  DASH, in comparison is light and snappy, thus greatly improving the time it takes your computer to boot.  If your scripts are adhering to POSIX standards, and are using /bin/sh rather than /bin/bash, you shouldn&#8217;t notice any problems.  However, if your scripts are relying on /bin/bash features, such as popd or pushd, and you change the interpreter at the top of your script to /bin/sh, you&#8217;ll have some breakage.</p><p>For what it&#8217;s worth, this isn&#8217;t anything new with 8.04.  DASH became the default in Ubuntu with 6.10, so we&#8217;ve had it in this manner for some time.  If you would like to change it, then point the symbolic link from /bin/sh to /bin/bash rather than /bin/dash, and you&#8217;re done.  However, as you may have noticed, it could cause some breakage if you Bourne-compatible scripts contain &#8220;Bashisms&#8221;.</p><p>Personally, I recommend the Z-shell (ZSH) to anyone looking for an alternative to DASH or BASH.  Much more capable, flexible and configurable shell.</p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2008/06/27/dash-on-ubuntu/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>My ZSH Prompt Improved</title><link>http://pthree.org/2008/03/29/my-zsh-prompt-improved/</link> <comments>http://pthree.org/2008/03/29/my-zsh-prompt-improved/#comments</comments> <pubDate>Sat, 29 Mar 2008 17:49:19 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Scripting]]></category><guid
isPermaLink="false">http://pthree.org/?p=564</guid> <description><![CDATA[I&#8217;ve been meaning to get to this for some time, but haven&#8217;t gotten around to it until today. In a previous post, I shared with the world my zsh PS1 variable. Well, I extended it a bit this morning making it more informative. First, I need to setup a scenario: I&#8217;m running screen locally on [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve been meaning to get to this for some time, but haven&#8217;t gotten around to it until today. <a
href="http://pthree.org/2008/01/31/my-zsh-prompt/">In a previous post</a>, I shared with the world my zsh PS1 variable.  Well, I extended it a bit this morning making it more informative.  First, I need to setup a scenario:</p><p>I&#8217;m running screen locally on my laptop (we&#8217;ll refer to it as SCREEN_L), and remotely on my server (we&#8217;ll refer to this one as SCREEN_R).  For SCREEN_L, there is a ~/.screenrc that I use to show what screen window buffer I&#8217;m using via the &#8220;hardstatus&#8221; directive.  My ~/.screenrc is thus:</p><pre>
aaron@kratos:~ 2609 % cat .screenrc
screen -t python 0
screen -t irssi 1
screen -t shell 2
screen -t notify 3
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]' </pre><p>That puts a nice status line at the bottom of my terminal, letting me know what screen buffer I&#8217;m in, as well as it&#8217;s title.  However, I don&#8217;t want to run a ~/.screenrc under SCREEN_R.  This just means yet another hardstatus line that I really don&#8217;t want (I value my pixels).  Rather, I would like to be notified what screen window I&#8217;m under, if any, in my prompt.  After a bit of digging, I came up with the solution.</p><p>First, the environment variable $WINDOW is keeping track of this automatically for me.  For example:</p><pre>
aaron@kratos:~ 2610 % echo "\"$WINDOW\""
""
aaron@kratos:~ 2611 % screen
aaron@kratos:~ 2612 % echo "\"$WINDOW\""
"0"
</pre><p>Perfect!  Now, to get it into my prompt.  This is easy with adding a little if logic to our ~/.zshrc:</p><div
class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/>2<br
/>3<br
/>4<br
/>5<br
/>6<br
/></div></td><td><div
class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> x<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$WINDOW</span>&quot;</span> = x <span
style="color: #7a0874; font-weight: bold;">&#93;</span>; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; <span
style="color: #007800;">SCREEN</span>=<span
style="color: #ff0000;">&quot;(<span
style="color: #007800;">$WINDOW</span>)&quot;</span><br
/> <span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; &nbsp; <span
style="color: #007800;">SCREEN</span>=<span
style="color: #ff0000;">&quot;&quot;</span><br
/> <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <span
style="color: #007800;">PS1</span>=<span
style="color: #ff0000;">&quot;%n@%m<span
style="color: #007800;">$SCREEN</span>:%~%(?..[%?]) %h %# &quot;</span></div></td></tr></tbody></table></div><p>What am I doing here?  Well, first off I&#8217;m checking to see if the $WINDOW variable is blank.  I&#8217;m using <i>x&#8221;$WINDOW&#8221; != x</i> for a simple reason.  Zsh is expecting a valid condition after &#8216;!=&#8217;.  Unfortunately, an empty string isn&#8217;t satisfying it.  So, I prepend the letter x to the $WINDOW variable, and test to make sure it doesn&#8217;t equal just &#8216;x&#8217;.  Second, if $WINDOW equals anything other than &#8216;x&#8217;, a SCREEN variable is defined with the $WINDOW variable contents wrapped in parenthesis.  This $SCREEN variable is then added to the prompt.</p><p>Now, I add this to my ~/.zshrc for my SCREEN_R, and I can see where I&#8217;m at in my screen session remotely without the need for a remote ~/.screenrc.  Here&#8217;s the results, also showing off exit code:</p><pre>
aaron@kratos:~ 2614 % screen
aaron@kratos(0):~ 2615 % ping foo
ping: unknown host foo
aaron@kratos(0):~[2] 2616 %
</pre><p>Cheers!</p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2008/03/29/my-zsh-prompt-improved/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Testing AlphaNumeric Arguments In Bash</title><link>http://pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/</link> <comments>http://pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/#comments</comments> <pubDate>Fri, 04 Jan 2008 04:22:19 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Scripting]]></category><guid
isPermaLink="false">http://www.pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/</guid> <description><![CDATA[Spending the evening working on my shell scripting, I thought I would jump into &#8220;Wicked Cool Shell Scripts&#8221; by Dave Taylor. In his script validalnum.sh, he has a test case to check if a user entered in valid alphabetic or numeric characters. His result is elegant and clean. I&#8217;ve changed up the script a bit [...]]]></description> <content:encoded><![CDATA[<p>Spending the evening working on my shell scripting, I thought I would jump into <a
href="http://books.google.com/books?id=Df7P1WyG87sC&#038;dq=wiked+cool+shell+scripts&#038;pg=PP1&#038;ots=dtSxskzGAG&#038;sig=M7gHEj_eb1OqKKZr3ijbE-gbWus&#038;hl=en&#038;prev=http://www.google.com/search?q=wiked+cool+shell+scripts&#038;ie=utf-8&#038;oe=utf-8&#038;rls=com.ubuntu:en-US:official&#038;client=firefox-a&#038;sa=X&#038;oi=print&#038;ct=title&#038;cad=one-book-with-thumbnail">&#8220;Wicked Cool Shell Scripts&#8221; by Dave Taylor</a>.  In his script validalnum.sh, he has a test case to check if a user entered in valid alphabetic or numeric characters.  His result is elegant and clean.  I&#8217;ve changed up the script a bit for clarity:</p><div
class="codecolorer-container bash twitlight" 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="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #666666; font-style: italic;">#!/bin/bash</span><br
/> <br
/> <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #660033;">-n</span> <span
style="color: #ff0000;">&quot;Enter alphanumeric input: &quot;</span><br
/> <span
style="color: #c20cb9; font-weight: bold;">read</span> input<br
/> <br
/> <span
style="color: #007800;">compressed</span>=<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$(echo $input | sed -e 's/[^[:alnum:]]//g')</span>&quot;</span><br
/> <br
/> <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$compressed</span>&quot;</span> <span
style="color: #000000; font-weight: bold;">!</span>= <span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$input</span>&quot;</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Input not valid.&quot;</span><br
/> <span
style="color: #000000; font-weight: bold;">else</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Input valid.&quot;</span><br
/> <span
style="color: #000000; font-weight: bold;">fi</span></div></td></tr></tbody></table></div><p>In this example, the user is asked to enter input that can be any combination of letters and numbers, regardless of case.  If the user enters punctuation, the test case fails, and the user is notified of such.  Otherwise, the test case passes, and everyone is happy.</p><p>I want to call to your attention the cornerstone of this script, however:</p><div
class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/></div></td><td><div
class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #007800;">compressed</span>=<span
style="color: #ff0000;">&quot;<span
style="color: #007800;">$(echo $input | sed -e 's/[^[:alnum:]]//g')</span>&quot;</span></div></td></tr></tbody></table></div><p>The variable $compressed is holding only alphanumeric characters.  This is done by taking the user input, and piping it to the stream editor sed.  With sed, we are searching for any character in the string that is not a number or a letter.  If such a character exists, we remove the character altogether.  Thus, if $compressed removes any characters, then it does not match what the user entered, and our test will fail.  If no characters were removed, then no punctuation exists in the input, and our test case will pass.</p><p>I thought this was most clever, and just had to share, hoping others benefit from this simple example.  I also hope that Dave is not mad at me for taking an example, changing it up a bit, and presenting it on this blog.  Thanks Dave.</p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2008/01/03/testing-alphanumeric-arguments-in-bash/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>Bash- The RIGHT Way</title><link>http://pthree.org/2007/05/12/bash-the-right-way/</link> <comments>http://pthree.org/2007/05/12/bash-the-right-way/#comments</comments> <pubDate>Sun, 13 May 2007 01:48:17 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Scripting]]></category><guid
isPermaLink="false">http://www.pthree.org/2007/05/12/bash-the-right-way/</guid> <description><![CDATA[I guess when you have GNU developing both the bash shell and the text editor emacs, you&#8217;re going to have one set of keyboard shortcuts work in the other. Case in point: the emacs keyboard shortcuts are also bound in the bash shell. Well, being a vim enthusiast, that just isn&#8217;t going to work. So, [...]]]></description> <content:encoded><![CDATA[<p>I guess when you have GNU developing both the bash shell and the text editor emacs, you&#8217;re going to have one set of keyboard shortcuts work in the other.  Case in point: the emacs keyboard shortcuts are also bound in the bash shell.</p><p>Well, being a vim enthusiast, that just isn&#8217;t going to work.  So, here&#8217;s something that I learned at my Ubuntu-Utah LoCo meeting that ended just 20 minutes ago:</p><div
class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/></div></td><td><div
class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">aaron<span
style="color: #000000; font-weight: bold;">@</span>hercules:~$ <span
style="color: #000000; font-weight: bold;">set</span> <span
style="color: #660033;">-o</span> <span
style="color: #c20cb9; font-weight: bold;">vi</span></div></td></tr></tbody></table></div><p>Oh yeah.  That&#8217;s better.  When executed, you are in insert mode, and not command mode.  So, to take advantage of the vim keyboard shortcuts, &#8216;esc&#8217; or &#8216;ctrl-[&#8216; to get into command mode, and hack away!  Make sure to add this to your ~/.bashrc.</p><p>You&#8217;re welcome. <img
src='http://pthree.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2007/05/12/bash-the-right-way/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> <item><title>Irssi GUI Notify- The Bash Script</title><link>http://pthree.org/2007/03/22/irssi-gui-notify-the-bash-script/</link> <comments>http://pthree.org/2007/03/22/irssi-gui-notify-the-bash-script/#comments</comments> <pubDate>Thu, 22 Mar 2007 13:12:39 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Scripting]]></category><guid
isPermaLink="false">http://www.pthree.org/2007/03/22/irssi-gui-notify-the-bash-script/</guid> <description><![CDATA[Apparently, people are having issues with the Bash script in my previous post. There is a syntax error, and they can&#8217;t get it working. The error is something along these lines: aaron@poseidon:~$ bash irssi_notify.sh irssi_notify.sh: 3: Syntax error: "done" unexpected (expecting "do") The problem is a missing semi-colon after the word &#8220;message&#8221; just before the [...]]]></description> <content:encoded><![CDATA[<p>Apparently, people are having issues with the Bash script in my previous post.  There is a syntax error, and they can&#8217;t get it working.  The error is something along these lines:</p><pre>aaron@poseidon:~$ bash irssi_notify.sh
irssi_notify.sh: 3: Syntax error: "done" unexpected (expecting "do")</pre><p>The problem is a missing semi-colon after the word &#8220;message&#8221; just before the word &#8220;do&#8221;.  So, it should read something like this:</p><pre>...while read heading message;  do  /usr/bin/notify-send...</pre><p>I have an updated copy. <a
href="http://www.pthree.org/wp-content/uploads/2007/03/irssi_notify.sh">You can grab it here</a>.  Just replace &#8216;user@server&#8217; with whatever is appropriate for you.</p><p>Because the Bash script is the most hackish of this notification solution, here is what I recommend doing with it:</p><ul><li>Obviously, save it in a location where you won&#8217;t delete it later.</li><li>Pull up a terminal and run screen.  If you don&#8217;t have screen installed, &#8216;sudo aptitude install screen&#8217;.</li><li>Run the bash script &#8216;bash irssi_notify.sh&#8217;</li><li>Detach the screen session by pressing &#8216;ctrl-a ctrl-d&#8217; in that order.</li><li>Exit the terminal you just pulled up</li></ul><p>The script is now running in the background.  When you change locations, you&#8217;ll need to stop the bash script before you leave your current location.  So:</p><ul><li>Pull up a terminal and reattach your screen session: &#8216;screen -dr&#8217;</li><li>Cancel the script with &#8216;ctrl-c&#8217;.  It should still be running.</li><li>Exit your terminal</li></ul><p>Again, not the most elegant, but it works, and works well.  Of course, if you have any questions, feel free to <a
href="http://www.pthree.org/contact/">email me</a>, comment on either post, or visit me in #ubuntu-us.</p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2007/03/22/irssi-gui-notify-the-bash-script/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>Irssi GUI Notify</title><link>http://pthree.org/2007/03/21/irssi-gui-notify/</link> <comments>http://pthree.org/2007/03/21/irssi-gui-notify/#comments</comments> <pubDate>Thu, 22 Mar 2007 02:45:13 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Perl]]></category> <category><![CDATA[Scripting]]></category><guid
isPermaLink="false">http://www.pthree.org/2007/03/21/irssi-gui-notify/</guid> <description><![CDATA[I am currently connected to two Irssi instances coupled with screen. One instance at home, for all my personal IRC needs, and the other at a corporate LAN for secure inter-office IRC messaging. It works great, except when someone tries to get a hold of you (a highlight). I haven&#8217;t found any good way for [...]]]></description> <content:encoded><![CDATA[<p>I am currently connected to two Irssi instances coupled with screen.  One instance at home, for all my personal IRC needs, and the other at a corporate LAN for secure inter-office IRC messaging.  It works great, except when someone tries to get a hold of you (a highlight).  I haven&#8217;t found any good way for Irssi to notify you when you have been highlighted in a channel.  For the past couple years, it hasn&#8217;t been bothering me.  Then, I found a pretty slick notification system for Irssi, and now I&#8217;m hooked. Here is a how-to for getting a GUI notification on your desktop (Gnome or KDE) when someone highlights you in a channel.</p><p>For this tutorial, it assumes that Irssi is running on a box separate from your current local machine that you have SSH access to.  For example, at work, we have an inter-office server that is running an IRC server.  I just SSH into that server from my workstation, fire up screen then Irssi, and connect to it.  Irssi is running remotely from my desktop.  This is also the case for my personal Irssi session.  So, in other words, Irssi is running under screen remotely, and you connect to that session from any other computer via SSH.</p><p>First, there is <a
href="http://thorstenl.blogspot.com/2007/01/thls-irssi-notification-script.html">fnotify.pl</a>, a Perl script for Irssi to save the highlights you get in a channel to a file.  Save this script to your ~/.irssi/scripts/ directory:</p><pre>aaron@achilles:~$ mv fnotify.pl ~/.irssi/scripts</pre><p>Now, if you want the script to run automatically when you launch Irssi, then create a directory called &#8216;autorun&#8217; in the ~/.irssi/scripts/ directory, and create a symbolic link to fnotify.pl so Irssi starts it up automatically when loaded:</p><pre>aaron@achilles:~$ cd ~/.irssi/scripts/autorun &#038;&#038; ln -s ../fnotify.pl .</pre><p>Once copied in, either start your Irssi session, or if it is already running, then execute the script in Irssi itself:</p><pre>/RUN fnotify.pl</pre><p>When running, it creates a file called &#8216;fnotify&#8217; in the ~/.irssi/ directory.  It is just a plain text file containing all the times you have been highlighted in a channel, one highlight per line.</p><p>We need to get the highlights in the appropriate channel to our desktop, so we can visually see them when we are not looking at Irssi itself. You will need notify-send to notify you when someone says your name in a channel.  If not installed, install libnotify-bin (Ubuntu/Debian syntax below):</p><pre>aaron@hercules:~$ sudo aptitude install libnotify-bin</pre><p>Now, we just need to write a shell script to send us the GUI notifications.  This can be done with a <a
href="http://thorstenl.blogspot.com/2007/01/thls-irssi-notification-script.html">simple Bash script</a> (yes, from the same page we got the Perl script for Irssi).  Save it anywhere on your local box (not the box that is running the Irssi instance; like your workstation, for example) and execute it (here, I saved it as &#8216;irssi_notify.sh&#8217;).</p><p>In the script above, you need to replace &#8216;remote.system.somewhere&#8217; with your server that you are connecting to.  The script makes an SSH connection to the server that you specified, and parses through ~/.irssi/fnotify one line at a time.  Each line gets its own notification.  That line is then removed from the file, so it doesn&#8217;t continuously grow as you continue to get highlighted in channels.</p><p>There you go.  That&#8217;s it!  Pretty easy, but a little hackish.  But that&#8217;s okay.  Isn&#8217;t that what computers are all about?  To automate human tasks?  Besides, what fun would it be, if it weren&#8217;t hackish?  At any rate, a screenshot of the notification results is shown below (you can see the notifications in the bottom-right of the screenshot).  But first, a couple caveats:</p><p>1. If the screensaver kicks in, and you are highlighted in a channel, you will not receive a GUI notification.  This is default behavior with libnotify-bin.<br
/> 2. By default, Irssi only highlights the nick that mentioned your nick if your nick is first on the line.  Otherwise, it is not the case.  This can be fixed highlighting the nick that mentions your nick anywhere in the text.  Do the following in Irssi:</p><pre>/hilight -nick (your_nick)</pre><p>Thanks to <a
href="http://fedora-tutorials.com/2007/03/20/fedora-people-rule/">Clint</a> for bringing this to my attention!  Click for a larger screenshot.</p><p><a
href='http://www.pthree.org/wp-content/uploads/2007/03/irssi_notify.png' border='0'><img
src='http://www.pthree.org/wp-content/uploads/2007/03/irssi_notify.thumbnail.png' alt='irssi_notify.png' /></a></p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2007/03/21/irssi-gui-notify/feed/</wfw:commentRss> <slash:comments>18</slash:comments> </item> <item><title>Poll: First Programming Language?</title><link>http://pthree.org/2007/03/13/poll-first-programming-language/</link> <comments>http://pthree.org/2007/03/13/poll-first-programming-language/#comments</comments> <pubDate>Tue, 13 Mar 2007 16:47:19 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Perl]]></category> <category><![CDATA[Python]]></category> <category><![CDATA[Ruby]]></category> <category><![CDATA[Scripting]]></category><guid
isPermaLink="false">http://www.pthree.org/2007/03/13/poll-first-programming-language/</guid> <description><![CDATA[My coworker asked me this question, and began asking a few others in a couple IRC channels. So, I thought I&#8217;d extend it to my blog, and the planets that I syndicate. I added as many choices as I could hoping to see a wide array of votes. I added a few newer languages for [...]]]></description> <content:encoded><![CDATA[<p>My coworker asked me this question, and began asking a few others in a couple IRC channels.  So, I thought I&#8217;d extend it to my blog, and the planets that I syndicate.  I added as many choices as I could hoping to see a wide array of votes.  I added a few newer languages for the younger audience.</p><p>For me, my first language that I sat down and learned in a formal setting was Java.  However, I had TI, Casio, and HP calculators, as well as an Atari 800 that I would fiddle with, and program.  So, Basic was really the first language that I toyed with.  I just never sat down, and took the time to &#8220;learn&#8221; it.</p><p>So, for all the programmers, coders, script kiddies and developers out there, what is the 1st programming language that you learned?  If applicable, leave a comment specifying the system that you learned the language on.</p><div><div
class='democracy'> <strong
class="poll-question">What was the 1st programming language that you learned?</strong><div
class='dem-results'><form
action='http://pthree.org/wp-content/plugins/democracy/democracy.php' onsubmit='return dem_Vote(this)'><ul><li> <input
type='radio' id='dem-choice-19' value='19' name='dem_poll_4' /> <label
for='dem-choice-19'>Basic</label></li><li> <input
type='radio' id='dem-choice-20' value='20' name='dem_poll_4' /> <label
for='dem-choice-20'>Pascal</label></li><li> <input
type='radio' id='dem-choice-21' value='21' name='dem_poll_4' /> <label
for='dem-choice-21'>C</label></li><li> <input
type='radio' id='dem-choice-22' value='22' name='dem_poll_4' /> <label
for='dem-choice-22'>Perl</label></li><li> <input
type='radio' id='dem-choice-23' value='23' name='dem_poll_4' /> <label
for='dem-choice-23'>Lisp</label></li><li> <input
type='radio' id='dem-choice-24' value='24' name='dem_poll_4' /> <label
for='dem-choice-24'>Fortran</label></li><li> <input
type='radio' id='dem-choice-25' value='25' name='dem_poll_4' /> <label
for='dem-choice-25'>Assembly</label></li><li> <input
type='radio' id='dem-choice-26' value='26' name='dem_poll_4' /> <label
for='dem-choice-26'>PHP</label></li><li> <input
type='radio' id='dem-choice-27' value='27' name='dem_poll_4' /> <label
for='dem-choice-27'>ASP / ASP.NET</label></li><li> <input
type='radio' id='dem-choice-28' value='28' name='dem_poll_4' /> <label
for='dem-choice-28'>C++</label></li><li> <input
type='radio' id='dem-choice-29' value='29' name='dem_poll_4' /> <label
for='dem-choice-29'>Python</label></li><li> <input
type='radio' id='dem-choice-30' value='30' name='dem_poll_4' /> <label
for='dem-choice-30'>Java</label></li><li> <input
type='radio' id='dem-choice-31' value='31' name='dem_poll_4' /> <label
for='dem-choice-31'>sh / csh / bash</label></li><li> <input
type='radio' id='dem-choice-32' value='32' name='dem_poll_4' /> <label
for='dem-choice-32'>Ruby</label></li><li> <input
type='radio' id='dem-choice-33' value='33' name='dem_poll_4' /> <label
for='dem-choice-33'>Other</label></li></ul> <input
type='hidden' name='dem_poll_id' value='4' /> <input
type='hidden' name='dem_action' value='vote' /> <input
type='submit' class='dem-vote-button' value='Vote' /> <a
href='/category/scripting/feed/?dem_action=view&amp;dem_poll_id=4' onclick='return dem_getVotes("http://pthree.org/wp-content/plugins/democracy/democracy.php?dem_action=view&amp;dem_poll_id=4", this)' rel='nofollow' class='dem-vote-link'>View Results</a></form></div></div></div> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2007/03/13/poll-first-programming-language/feed/</wfw:commentRss> <slash:comments>46</slash:comments> </item> <item><title>WordPress Upgrade Script</title><link>http://pthree.org/2007/03/02/wordpress-upgrade-script/</link> <comments>http://pthree.org/2007/03/02/wordpress-upgrade-script/#comments</comments> <pubDate>Sat, 03 Mar 2007 05:45:59 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Blogging]]></category> <category><![CDATA[Scripting]]></category> <category><![CDATA[Wordpress]]></category><guid
isPermaLink="false">http://www.pthree.org/2007/03/02/wordpress-upgrade-script/</guid> <description><![CDATA[For those of you running WordPress on your own server, or a server that you maintain, I wrote a little script that may make upgrading your WordPress a bit easier. For me, I am running 4 installations of WordPress, so, when the upgrades are released, it&#8217;s a bit of a pain to get them all [...]]]></description> <content:encoded><![CDATA[<p>For those of you running WordPress on your own server, or a server that you maintain, I wrote a little script that may make upgrading your WordPress a bit easier.  For me, I am running 4 installations of WordPress, so, when the upgrades are released, it&#8217;s a bit of a pain to get them all into shape.  So, thanks to <a
href="http://ubuntu-tutorials.com">Christer</a> for the idea, I wrote a script that takes care of the job 10 times faster than if I were to do it by hand.</p><p>First, I should mention that this script comes with no warranty what-so-ever.  Use it at your own risk.  If you foul up your database or WordPress install, don&#8217;t come crying to me.  Although this upgraded my 4 installations without hitch, this does not necessarily mean that it will work for you.  Please use caution when upgrading the files and the database.  If you do run into problems, I will try to provide necessary support as possible.  However, I am very busy, so it may be faster for you to figure out what happened, and to fix it on your own.  You&#8217;ll learn better that way anyway.</p><p>Next, this script follows the <a
href="http://codex.wordpress.org/Upgrading_WordPress#Detailed_Instructions">detailed instructions</a> as closely as possible.  Namely:</p><ul><li>Your existing WordPress install is backed up, just in case.</li><li>All databases are backed up.</li><li>All necessary and important files (.htaccess, wp-config, etc) and directories are backed up.</li><li>The latest release is downloaded.</li><li>All files are upgraded.</li></ul><p>Of course, it is your job to navigate your browser to the appropriate PHP upgrade page for every WordPress installation that is upgraded, and verify that all plugins, permalinks and themes work.</p><p>At any rate, here is the code: a simple Bash script.  The version of the script is 0.1.2.</p><div
class="codecolorer-container bash twitlight" 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
/>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
/>74<br
/>75<br
/>76<br
/>77<br
/>78<br
/>79<br
/>80<br
/>81<br
/>82<br
/>83<br
/>84<br
/>85<br
/>86<br
/>87<br
/>88<br
/>89<br
/>90<br
/>91<br
/>92<br
/>93<br
/>94<br
/>95<br
/>96<br
/>97<br
/>98<br
/>99<br
/>100<br
/>101<br
/>102<br
/>103<br
/></div></td><td><div
class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #666666; font-style: italic;">#!/bin/bash</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># This program upgrades your existing Wordpress installations that you are running on your server.</span><br
/> <span
style="color: #666666; font-style: italic;">#</span><br
/> <span
style="color: #666666; font-style: italic;"># You need to make the necessary adjustments to this script as needed for your situation.</span><br
/> <span
style="color: #666666; font-style: italic;">#</span><br
/> <span
style="color: #666666; font-style: italic;"># Make this script executable: 'chmod 777 wp_upgrade.sh'</span><br
/> <span
style="color: #666666; font-style: italic;"># Run the script: './wp_upgrade.sh'</span><br
/> <span
style="color: #666666; font-style: italic;">#</span><br
/> <span
style="color: #666666; font-style: italic;"># Author: Aaron Toponce</span><br
/> <span
style="color: #666666; font-style: italic;"># License: GPL v2</span><br
/> <span
style="color: #666666; font-style: italic;"># Version: 0.1.2</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># =================== Start of Script =================== #</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># Provide the necessary directories to what Wordpress installations need to be backed up space delimited</span><br
/> <span
style="color: #666666; font-style: italic;"># Change as necessary and uncomment</span><br
/> <span
style="color: #666666; font-style: italic;"># For example, if you had 3 sites in /var/www/site1, /var/www/site2 and /var/www/site3</span><br
/> <span
style="color: #666666; font-style: italic;"># then it would look like below (do not add the trailing slash):</span><br
/> <span
style="color: #666666; font-style: italic;"># directories=(/var/www/site1 /var/www/site2 /var/www/site3)</span><br
/> <span
style="color: #007800;">number</span>=<span
style="color: #800000;">${#directories[@]}</span><br
/> <span
style="color: #666666; font-style: italic;"># Testing that all directories specified above are valid before beginning</span><br
/> <span
style="color: #000000; font-weight: bold;">for</span> <span
style="color: #7a0874; font-weight: bold;">&#40;</span><span
style="color: #7a0874; font-weight: bold;">&#40;</span> i = <span
style="color: #000000;">0</span> ; i <span
style="color: #000000; font-weight: bold;">&lt;</span> number ; i++ <span
style="color: #7a0874; font-weight: bold;">&#41;</span><span
style="color: #7a0874; font-weight: bold;">&#41;</span>; <span
style="color: #000000; font-weight: bold;">do</span><br
/> &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span><span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #000000; font-weight: bold;">!</span> <span
style="color: #660033;">-d</span> <span
style="color: #800000;">${directories[$i]}</span> <span
style="color: #7a0874; font-weight: bold;">&#93;</span><span
style="color: #7a0874; font-weight: bold;">&#93;</span>; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Directory <span
style="color: #007800;">${$directories[$i]}</span> does not exist.&quot;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">return</span> <span
style="color: #000000;">1</span><br
/> &nbsp; &nbsp; <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <span
style="color: #000000; font-weight: bold;">done</span><br
/> <br
/> <span
style="color: #666666; font-style: italic;"># First, we need to get the necessary file</span><br
/> <span
style="color: #7a0874; font-weight: bold;">cd</span> ~<br
/> <br
/> <span
style="color: #000000; font-weight: bold;">if</span> <span
style="color: #7a0874; font-weight: bold;">&#91;</span><span
style="color: #7a0874; font-weight: bold;">&#91;</span> <span
style="color: #660033;">-f</span> wordpress.tar.gz <span
style="color: #7a0874; font-weight: bold;">&#93;</span><span
style="color: #7a0874; font-weight: bold;">&#93;</span>; <span
style="color: #000000; font-weight: bold;">then</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;wordpress.tar.gz exists. &nbsp;Please take notice to this upgrade before continuing.&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">return</span> <span
style="color: #000000;">1</span><br
/> <span
style="color: #000000; font-weight: bold;">fi</span><br
/> <br
/> <span
style="color: #c20cb9; font-weight: bold;">wget</span> <span
style="color: #660033;">-O</span> latest.tar.gz http:<span
style="color: #000000; font-weight: bold;">//</span>wordpress.org<span
style="color: #000000; font-weight: bold;">/</span>latest.tar.gz<br
/> <br
/> <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;First disable all plugins on all installations before continuing.&quot;</span><br
/> <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Press ENTER to continue...&quot;</span><br
/> <span
style="color: #c20cb9; font-weight: bold;">read</span> blah<br
/> <br
/> <span
style="color: #000000; font-weight: bold;">for</span> <span
style="color: #7a0874; font-weight: bold;">&#40;</span><span
style="color: #7a0874; font-weight: bold;">&#40;</span> i = <span
style="color: #000000;">0</span> ; i <span
style="color: #000000; font-weight: bold;">&lt;</span> number ; i++ <span
style="color: #7a0874; font-weight: bold;">&#41;</span><span
style="color: #7a0874; font-weight: bold;">&#41;</span>; <span
style="color: #000000; font-weight: bold;">do</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">clear</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">cd</span> <span
style="color: #800000;">${directories[$i]}</span><br
/> <br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;We are backing up the full directory, in case anything goes wrong. Press ENTER...&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">read</span> blah<br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">cd</span> ..<span
style="color: #000000; font-weight: bold;">/</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">tar</span> <span
style="color: #660033;">-cvvf</span> <span
style="color: #800000;">${directories[$i]}</span>.tar <span
style="color: #800000;">${directories[$i]}</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">gzip</span> &nbsp;<span
style="color: #800000;">${directories[$i]}</span>.tar<br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">cd</span> <span
style="color: #800000;">${directories[$i]}</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">mv</span> <span
style="color: #800000;">${directories[$i]}</span>.tar.gz .<br
/> &nbsp; &nbsp; <br
/> &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;"># Timestamp in unix epoch format to create unique backup directories</span><br
/> &nbsp; &nbsp; <span
style="color: #007800;">back_ts</span>=$<span
style="color: #7a0874; font-weight: bold;">&#40;</span><span
style="color: #c20cb9; font-weight: bold;">date</span> +<span
style="color: #000000; font-weight: bold;">%</span>s<span
style="color: #7a0874; font-weight: bold;">&#41;</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">mkdir</span> backup_<span
style="color: #800000;">${back_ts}</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <br
/> &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;"># Backing up the necessary Wordpress database</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Please provide the wordpress database name (case sensitive) for <span
style="color: #007800;">${directories[$i]}</span>:&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">read</span> wp_db<br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;And please provide the username to the database:&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">read</span> wp_user<br
/> &nbsp; &nbsp; mysqldump <span
style="color: #660033;">--add-drop-table</span> <span
style="color: #660033;">-u</span> <span
style="color: #800000;">${wp_user}</span> <span
style="color: #660033;">-p</span> <span
style="color: #800000;">${wp_db}</span> <span
style="color: #000000; font-weight: bold;">&gt;</span> backup_<span
style="color: #800000;">${back_ts}</span><span
style="color: #000000; font-weight: bold;">/</span><span
style="color: #800000;">${wp_db}</span>.sql<br
/> &nbsp; &nbsp; &nbsp; &nbsp; <br
/> &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;"># Make the necessary changes for what to backup. &nbsp;This is the default as provided by Wordpress.</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Backing up the important files. Press ENTER...&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">read</span> blah<br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">cp</span> .htaccess wp-config.php backup_<span
style="color: #800000;">${back_ts}</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">cp</span> <span
style="color: #660033;">-r</span> wp-content wp-images wp-includes<span
style="color: #000000; font-weight: bold;">/</span>languages backup_<span
style="color: #800000;">${back_ts}</span><br
/> &nbsp; &nbsp; <br
/> &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;"># Time to copy the latest wordpress that we downloaded and overwrite all files</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Getting the latest cp of wordpress. Press ENTER...&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">read</span> blah<br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">cp</span> ~<span
style="color: #000000; font-weight: bold;">/</span>latest.tar.gz .<span
style="color: #000000; font-weight: bold;">/</span>wordpress.tar.gz<br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">tar</span> <span
style="color: #660033;">-zxvf</span> wordpress.tar.gz<br
/> <br
/> &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;"># Overwrite all files</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Overwriting all old Wordpress files with the new. Press ENTER...&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">read</span> blah<br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">cd</span> wordpress<br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">cp</span> <span
style="color: #660033;">-rf</span> <span
style="color: #000000; font-weight: bold;">*</span> ..<span
style="color: #000000; font-weight: bold;">/</span><br
/> <br
/> &nbsp; &nbsp; <span
style="color: #666666; font-style: italic;"># Copy the files that we backed up back</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Coping the important backed up files back in. Press ENTER...&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">read</span> blah<br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">cd</span> ..<span
style="color: #000000; font-weight: bold;">/</span>backup_<span
style="color: #800000;">${back_ts}</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">cp</span> <span
style="color: #660033;">-rf</span> <span
style="color: #000000; font-weight: bold;">*</span> ..<span
style="color: #000000; font-weight: bold;">/</span><br
/> <br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Point your browser to the necessary site and run the upgrade script.&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;EG: http://example.com/wp-admin/upgrade.php&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Update your permalinks and .htaccess.&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Install updated plugins and themes&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Reactivate plugins&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Press ENTER to continue...&quot;</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">read</span> blah<br
/> <span
style="color: #000000; font-weight: bold;">done</span><br
/> <br
/> <span
style="color: #c20cb9; font-weight: bold;">clear</span><br
/> <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Congratulations! You have successfully upgraded your Wordpress.&quot;</span><br
/> <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Please review that your browser resolves your site.&quot;</span><br
/> <span
style="color: #7a0874; font-weight: bold;">echo</span> <span
style="color: #ff0000;">&quot;Enjoy!&quot;</span></div></td></tr></tbody></table></div> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2007/03/02/wordpress-upgrade-script/feed/</wfw:commentRss> <slash:comments>17</slash:comments> </item> <item><title>Perl Versus Ruby on CSV</title><link>http://pthree.org/2006/12/29/perl-versus-ruby-on-csv/</link> <comments>http://pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comments</comments> <pubDate>Sat, 30 Dec 2006 02:15:13 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Perl]]></category> <category><![CDATA[Ruby]]></category> <category><![CDATA[Scripting]]></category><guid
isPermaLink="false">http://www.pthree.org/2006/12/29/perl-versus-ruby-on-csv/</guid> <description><![CDATA[Ok. I had a little project at work, at which point, I turned to Perl to accomplish the task. The project was simple enough: take a comma-separated file, and look at a few fields to see what data is contained. Based on that data, create a &#8220;weight&#8221;, and assign the weight to the record at [...]]]></description> <content:encoded><![CDATA[<p>Ok.  I had a little project at work, at which point, I turned to Perl to accomplish the task.  The project was simple enough: take a comma-separated file, and look at a few fields to see what data is contained.  Based on that data, create a &#8220;weight&#8221;, and assign the weight to the record at the end of the line.</p><p>The Perl code I used to accomplish the task is as follows (please take note, that WordPress loves to parse tags, even if contained within &lt;code&gt; tags.  WordPress also likes to lowercase the tag, so in Perl, file handles will be in lowercase):</p><div
class="codecolorer-container perl twitlight" 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
/></div></td><td><div
class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #666666; font-style: italic;">#!/usr/bin/perl -w</span><br
/> <br
/> <span
style="color: #000066;">open</span><span
style="color: #009900;">&#40;</span>IN<span
style="color: #339933;">,</span> <span
style="color: #ff0000;">&quot;UNIVERSE.csv&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> <span
style="color: #000066;">open</span><span
style="color: #009900;">&#40;</span>OUT<span
style="color: #339933;">,</span> <span
style="color: #ff0000;">&quot;&gt;UNIVERSE_WEIGHTED.csv&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> <br
/> <span
style="color: #0000ff;">$counter</span> <span
style="color: #339933;">=</span> <span
style="color: #cc66cc;">0</span><span
style="color: #339933;">;</span><br
/> <br
/> <span
style="color: #b1b100;">while</span><span
style="color: #009900;">&#40;</span><span
style="color: #009999;">&lt;in&gt;</span><span
style="color: #009900;">&#41;</span> <span
style="color: #666666; font-style: italic;"># &lt;/in&gt; (for Wordpress)</span><br
/> <span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; <span
style="color: #0000ff;">@fields</span> <span
style="color: #339933;">=</span> <span
style="color: #000066;">split</span><span
style="color: #009900;">&#40;</span><span
style="color: #009966; font-style: italic;">/,/</span><span
style="color: #339933;">,</span><span
style="color: #0000ff;">$_</span><span
style="color: #339933;">,</span><span
style="color: #cc66cc;">183</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <span
style="color: #0000ff;">$fields</span><span
style="color: #009900;">&#91;</span><span
style="color: #cc66cc;">182</span><span
style="color: #009900;">&#93;</span> <span
style="color: #339933;">=~</span> <span
style="color: #009966; font-style: italic;">s/\n//</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <span
style="color: #009966; font-style: italic;">s/\n//</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <span
style="color: #0000ff;">$counter</span><span
style="color: #339933;">++;</span><br
/> &nbsp; &nbsp; <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">=</span> <span
style="color: #cc66cc;">0</span><span
style="color: #339933;">;</span><br
/> <br
/> &nbsp; &nbsp; <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">$counter</span> <span
style="color: #339933;">==</span> <span
style="color: #cc66cc;">1</span><span
style="color: #009900;">&#41;</span><br
/> &nbsp; &nbsp; <span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000066;">print</span> OUT <span
style="color: #0000ff;">$_</span> <span
style="color: #339933;">.</span> <span
style="color: #ff0000;">&quot;,<span
style="color: #000099; font-weight: bold;">\&quot;</span>weight<span
style="color: #000099; font-weight: bold;">\&quot;</span><span
style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <span
style="color: #009900;">&#125;</span><br
/> &nbsp; &nbsp; <span
style="color: #b1b100;">else</span><br
/> &nbsp; &nbsp; <span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$vtr_ppp00</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">$fields</span><span
style="color: #009900;">&#91;</span><span
style="color: #cc66cc;">154</span><span
style="color: #009900;">&#93;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$vtr_ppp04</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">$fields</span><span
style="color: #009900;">&#91;</span><span
style="color: #cc66cc;">155</span><span
style="color: #009900;">&#93;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$vtr_pri01</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">$fields</span><span
style="color: #009900;">&#91;</span><span
style="color: #cc66cc;">161</span><span
style="color: #009900;">&#93;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$vtr_pri03</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">$fields</span><span
style="color: #009900;">&#91;</span><span
style="color: #cc66cc;">163</span><span
style="color: #009900;">&#93;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$vtr_pri05</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">$fields</span><span
style="color: #009900;">&#91;</span><span
style="color: #cc66cc;">165</span><span
style="color: #009900;">&#93;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$vtr_pri99</span> <span
style="color: #339933;">=</span> <span
style="color: #0000ff;">$fields</span><span
style="color: #009900;">&#91;</span><span
style="color: #cc66cc;">182</span><span
style="color: #009900;">&#93;</span><span
style="color: #339933;">;</span><br
/> <br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">+=.</span>5 <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">$vtr_ppp00</span> <span
style="color: #b1b100;">eq</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\&quot;</span>R<span
style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">-=</span> <span
style="color: #cc66cc;">1</span> <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">$vtr_ppp04</span> <span
style="color: #b1b100;">eq</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\&quot;</span>D<span
style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">-=</span> <span
style="color: #cc66cc;">1</span> <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">$vtr_pri01</span> <span
style="color: #b1b100;">eq</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\&quot;</span>D<span
style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">-=</span> <span
style="color: #cc66cc;">1</span> <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">$vtr_pri03</span> <span
style="color: #b1b100;">eq</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\&quot;</span>D<span
style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">-=</span> <span
style="color: #cc66cc;">1</span> <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">$vtr_pri05</span> <span
style="color: #b1b100;">eq</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\&quot;</span>D<span
style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">-=</span> <span
style="color: #cc66cc;">1</span> <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">$vtr_pri99</span> <span
style="color: #b1b100;">eq</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\&quot;</span>D<span
style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">+=</span> <span
style="color: #cc66cc;">1</span> <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">$vtr_ppp04</span> <span
style="color: #b1b100;">eq</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\&quot;</span>R<span
style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">+=</span> <span
style="color: #cc66cc;">1</span> <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">$vtr_pri01</span> <span
style="color: #b1b100;">eq</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\&quot;</span>R<span
style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">+=</span> <span
style="color: #cc66cc;">1</span> <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">$vtr_pri03</span> <span
style="color: #b1b100;">eq</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\&quot;</span>R<span
style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">+=</span> <span
style="color: #cc66cc;">1</span> <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">$vtr_pri05</span> <span
style="color: #b1b100;">eq</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\&quot;</span>R<span
style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">+=</span> <span
style="color: #cc66cc;">1</span> <span
style="color: #b1b100;">if</span> <span
style="color: #009900;">&#40;</span><span
style="color: #0000ff;">$vtr_pri99</span> <span
style="color: #b1b100;">eq</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\&quot;</span>R<span
style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <br
/> &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #000066;">print</span> OUT <span
style="color: #0000ff;">$_</span> <span
style="color: #339933;">.</span> <span
style="color: #ff0000;">&quot;,<span
style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span
style="color: #339933;">.</span> <span
style="color: #0000ff;">$weight</span> <span
style="color: #339933;">.</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\&quot;</span><span
style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; <span
style="color: #009900;">&#125;</span><br
/> &nbsp; &nbsp; <br
/> &nbsp; &nbsp; <span
style="color: #000066;">print</span> <span
style="color: #ff0000;">&quot;Processed: &quot;</span> <span
style="color: #339933;">.</span> <span
style="color: #0000ff;">$counter</span> <span
style="color: #339933;">.</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span
style="color: #339933;">;</span><br
/> <span
style="color: #009900;">&#125;</span><br
/> <br
/> <span
style="color: #000066;">print</span> <span
style="color: #ff0000;">&quot;<span
style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span
style="color: #339933;">;</span><br
/> <br
/> <span
style="color: #000066;">close</span><span
style="color: #009900;">&#40;</span>IN<span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> <span
style="color: #000066;">close</span><span
style="color: #009900;">&#40;</span>OUT<span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span></div></td></tr></tbody></table></div><p>Just for fun, a buddy of mine mentioned to code it in Ruby, and compare results.  Seeing as though I have never coded a Ruby script in my life, I was a bit worried.  However, it wasn&#8217;t too bad.  I just had to cure my itch to put a $ in front of all my variables.  Anyway, heres the Ruby code, following as closely as possible to the Perl code:</p><div
class="codecolorer-container ruby twitlight" 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
/></div></td><td><div
class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color:#008000; font-style:italic;">#!/usr/bin/ruby</span><br
/> <br
/> counter = <span
style="color:#006666;">0</span><br
/> <br
/> outfile = <span
style="color:#CC00FF; font-weight:bold;">File</span>.<span
style="color:#CC0066; font-weight:bold;">open</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#996600;">&quot;UNIVERSE_RUBY.csv&quot;</span>,<span
style="color:#996600;">&quot;w&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> <span
style="color:#CC00FF; font-weight:bold;">IO</span>.<span
style="color:#9900CC;">foreach</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#996600;">&quot;UNIVERSE.csv&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#9966CC; font-weight:bold;">do</span> <span
style="color:#006600; font-weight:bold;">|</span>line<span
style="color:#006600; font-weight:bold;">|</span><br
/> &nbsp; &nbsp; counter <span
style="color:#006600; font-weight:bold;">+</span>= <span
style="color:#006666;">1</span><br
/> &nbsp; &nbsp; weight = <span
style="color:#006666;">0</span><br
/> &nbsp; &nbsp; <br
/> &nbsp; &nbsp; <span
style="color:#9966CC; font-weight:bold;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>counter == <span
style="color:#006666;">1</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; outfile <span
style="color:#006600; font-weight:bold;">&lt;</span> <span
style="color:#006600; font-weight:bold;">&lt;</span> line.<span
style="color:#CC0066; font-weight:bold;">chop</span> <span
style="color:#006600; font-weight:bold;">+</span> <span
style="color:#996600;">&quot;,<span
style="color:#000099;">\&quot;</span>weight<span
style="color:#000099;">\&quot;</span><span
style="color:#000099;">\n</span>&quot;</span><br
/> &nbsp; &nbsp; <span
style="color:#9966CC; font-weight:bold;">else</span> &nbsp; &nbsp;<br
/> &nbsp; &nbsp; &nbsp; &nbsp; fields = line.<span
style="color:#CC0066; font-weight:bold;">chop</span>.<span
style="color:#CC0066; font-weight:bold;">split</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#996600;">','</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; vtr_ppp00 = fields<span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#006666;">154</span><span
style="color:#006600; font-weight:bold;">&#93;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; vtr_ppp04 = fields<span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#006666;">155</span><span
style="color:#006600; font-weight:bold;">&#93;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; vtr_pri01 = fields<span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#006666;">161</span><span
style="color:#006600; font-weight:bold;">&#93;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; vtr_pri03 = fields<span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#006666;">163</span><span
style="color:#006600; font-weight:bold;">&#93;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; vtr_pri05 = fields<span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#006666;">165</span><span
style="color:#006600; font-weight:bold;">&#93;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; vtr_pri99 = fields<span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#006666;">182</span><span
style="color:#006600; font-weight:bold;">&#93;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <br
/> &nbsp; &nbsp; &nbsp; &nbsp; weight <span
style="color:#006600; font-weight:bold;">+</span>= <span
style="color:#006666;">0.5</span> <span
style="color:#9966CC; font-weight:bold;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>vtr_ppp00 == <span
style="color:#996600;">&quot;<span
style="color:#000099;">\&quot;</span>R<span
style="color:#000099;">\&quot;</span>&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; weight <span
style="color:#006600; font-weight:bold;">-</span>= <span
style="color:#006666;">1</span> &nbsp; <span
style="color:#9966CC; font-weight:bold;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>vtr_ppp04 == <span
style="color:#996600;">&quot;<span
style="color:#000099;">\&quot;</span>D<span
style="color:#000099;">\&quot;</span>&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; weight <span
style="color:#006600; font-weight:bold;">-</span>= <span
style="color:#006666;">1</span> &nbsp; <span
style="color:#9966CC; font-weight:bold;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri01 == <span
style="color:#996600;">&quot;<span
style="color:#000099;">\&quot;</span>D<span
style="color:#000099;">\&quot;</span>&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; weight <span
style="color:#006600; font-weight:bold;">-</span>= <span
style="color:#006666;">1</span> &nbsp; <span
style="color:#9966CC; font-weight:bold;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri03 == <span
style="color:#996600;">&quot;<span
style="color:#000099;">\&quot;</span>D<span
style="color:#000099;">\&quot;</span>&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; weight <span
style="color:#006600; font-weight:bold;">-</span>= <span
style="color:#006666;">1</span> &nbsp; <span
style="color:#9966CC; font-weight:bold;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri05 == <span
style="color:#996600;">&quot;<span
style="color:#000099;">\&quot;</span>D<span
style="color:#000099;">\&quot;</span>&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; weight <span
style="color:#006600; font-weight:bold;">-</span>= <span
style="color:#006666;">1</span> &nbsp; <span
style="color:#9966CC; font-weight:bold;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri99 == <span
style="color:#996600;">&quot;<span
style="color:#000099;">\&quot;</span>D<span
style="color:#000099;">\&quot;</span>&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; weight <span
style="color:#006600; font-weight:bold;">+</span>= <span
style="color:#006666;">1</span> &nbsp; <span
style="color:#9966CC; font-weight:bold;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>vtr_ppp04 == <span
style="color:#996600;">&quot;<span
style="color:#000099;">\&quot;</span>R<span
style="color:#000099;">\&quot;</span>&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; weight <span
style="color:#006600; font-weight:bold;">+</span>= <span
style="color:#006666;">1</span> &nbsp; <span
style="color:#9966CC; font-weight:bold;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri01 == <span
style="color:#996600;">&quot;<span
style="color:#000099;">\&quot;</span>R<span
style="color:#000099;">\&quot;</span>&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; weight <span
style="color:#006600; font-weight:bold;">+</span>= <span
style="color:#006666;">1</span> &nbsp; <span
style="color:#9966CC; font-weight:bold;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri03 == <span
style="color:#996600;">&quot;<span
style="color:#000099;">\&quot;</span>R<span
style="color:#000099;">\&quot;</span>&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; weight <span
style="color:#006600; font-weight:bold;">+</span>= <span
style="color:#006666;">1</span> &nbsp; <span
style="color:#9966CC; font-weight:bold;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri05 == <span
style="color:#996600;">&quot;<span
style="color:#000099;">\&quot;</span>R<span
style="color:#000099;">\&quot;</span>&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; weight <span
style="color:#006600; font-weight:bold;">+</span>= <span
style="color:#006666;">1</span> &nbsp; <span
style="color:#9966CC; font-weight:bold;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>vtr_pri99 == <span
style="color:#996600;">&quot;<span
style="color:#000099;">\&quot;</span>R<span
style="color:#000099;">\&quot;</span>&quot;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><br
/> &nbsp; &nbsp; &nbsp; &nbsp; <br
/> &nbsp; &nbsp; &nbsp; &nbsp; outfile <span
style="color:#006600; font-weight:bold;">&lt;</span> <span
style="color:#006600; font-weight:bold;">&lt;</span> line.<span
style="color:#CC0066; font-weight:bold;">chop</span> <span
style="color:#006600; font-weight:bold;">+</span> <span
style="color:#996600;">&quot;,<span
style="color:#000099;">\&quot;</span>&quot;</span> <span
style="color:#006600; font-weight:bold;">+</span> weight.<span
style="color:#9900CC;">to_s</span> <span
style="color:#006600; font-weight:bold;">+</span> <span
style="color:#996600;">&quot;<span
style="color:#000099;">\&quot;</span><span
style="color:#000099;">\n</span>&quot;</span><br
/> &nbsp; &nbsp; <span
style="color:#9966CC; font-weight:bold;">end</span><br
/> &nbsp; &nbsp; <span
style="color:#CC0066; font-weight:bold;">print</span> <span
style="color:#996600;">&quot;Processed: &quot;</span> <span
style="color:#006600; font-weight:bold;">+</span> counter.<span
style="color:#9900CC;">to_s</span> <span
style="color:#006600; font-weight:bold;">+</span> <span
style="color:#996600;">&quot;<span
style="color:#000099;">\r</span>&quot;</span><br
/> <span
style="color:#9966CC; font-weight:bold;">end</span><br
/> <br
/> <span
style="color:#CC0066; font-weight:bold;">print</span> <span
style="color:#996600;">&quot;<span
style="color:#000099;">\n</span>&quot;</span></div></td></tr></tbody></table></div><p>Ok.  As you can see, the code is fairly similar.  The algorithms the same.  Running the script takes a mere second or two, and the file comes out correct.  However, I was curious about execution speed, so I decided to pit one script against the other, time them, and see what happens.  Here are my results</p><pre>
aaron@hercules:~/Desktop$ time perl weight.pl
Processed: 5394

real    0m1.386s
user    0m1.304s
sys     0m0.048s
aaron@hercules:~/Desktop$ time ruby weight.rb
Processed: 5394

real    0m2.180s
user    0m1.992s
sys     0m0.124s
</pre><p>Am I reading this correctly?  Perl is almost 60% faster at execution with this code than Ruby?  I thought Ruby was supposed to have exceptional file handling.  Better than Perl, even.  However, I have also heard that the Ruby devs are more concerned about functionality than speed, which should be expected.  Still, that&#8217;s a serious speed factor.  If I was worried about speed here, Perl, in this case, would win out.</p><p>At any rate, this was a fun little exercise to stretch my scripting muscles, and to learn a bit of Ruby.  I&#8217;m curious if I can make the scripts more efficient.  If you know how, comment below, or <a
href="http://www.pthree.org/contact">contact me</a>.</code></p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2006/12/29/perl-versus-ruby-on-csv/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>New Pthree Feature- Desktop Cam</title><link>http://pthree.org/2006/11/27/new-pthree-feature-desktop-cam/</link> <comments>http://pthree.org/2006/11/27/new-pthree-feature-desktop-cam/#comments</comments> <pubDate>Mon, 27 Nov 2006 07:03:36 +0000</pubDate> <dc:creator>Aaron</dc:creator> <category><![CDATA[Scripting]]></category><guid
isPermaLink="false">http://www.pthree.org/2006/11/27/new-pthree-feature-desktop-cam/</guid> <description><![CDATA[I&#8217;ve had this before on one of my previous blogs under the toponcefamily.com domain. I no longer own that domain (I let it expire, and now some &#8220;search engine&#8221; is selling it), but it was pretty cool. You could see what I was doing at anytime during the day. Well, I set it up again [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve had this before on one of my previous blogs under the toponcefamily.com domain.  I no longer own that domain (I let it expire, and now some &#8220;search engine&#8221; is selling it), but it was pretty cool.  You could see what I was doing at anytime during the day.</p><p>Well, I set it up again here on pthree.org.  Why, you ask?  Honestly, I don&#8217;t know.  Probably more for the geek factor than anything.  But at any event, it&#8217;s there, and cool.</p><p>Writing the code was really easy, actually.  The only trouble I had was setting up SSH to allow password-less secure copy.  Once that was up, a simple Bash script to capture the screenshot, resize the image, and send it to the server.  Here are the steps I followed to get my Desktop Cam up and running:</p><ol><li>Generate an SSH DSA key on the client that will be sending the image to the server.  The command was &#8216;ssh-keygen -t dsa&#8217;.</li><li>Append id_dsa.pub to the file &#8216;authorized_keys&#8217; on the server.  If the file doesn&#8217;t exist, create it.</li><li>Create the Bash script with a simple while loop that executes creating the image and copying to the server every 30 seconds.</li><li>Write the HTML for displaying the screenshot.</li><li>Write the JavaScript to refresh the image every 30 seconds also.</li></ol><p>For the Bash code, it was easy (text wrapped as necessary):</p><div
class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table
cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br
/>2<br
/>3<br
/>4<br
/>5<br
/>6<br
/>7<br
/>8<br
/></div></td><td><div
class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #666666; font-style: italic;">#!/bin/bash</span><br
/> <span
style="color: #c20cb9; font-weight: bold;">sleep</span> <span
style="color: #000000;">5</span><br
/> <span
style="color: #007800;">bool_test</span>=<span
style="color: #000000;">1</span><br
/> <span
style="color: #000000; font-weight: bold;">while</span> <span
style="color: #7a0874; font-weight: bold;">&#40;</span><span
style="color: #7a0874; font-weight: bold;">&#40;</span> bool_test == <span
style="color: #000000;">1</span> <span
style="color: #7a0874; font-weight: bold;">&#41;</span><span
style="color: #7a0874; font-weight: bold;">&#41;</span>; <span
style="color: #000000; font-weight: bold;">do</span><br
/> &nbsp; &nbsp; import <span
style="color: #660033;">-window</span> root <span
style="color: #660033;">-resize</span> <span
style="color: #000000;">512</span> ~<span
style="color: #000000; font-weight: bold;">/</span>DesktopCam.jpg<br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">scp</span> ~<span
style="color: #000000; font-weight: bold;">/</span>DesktopCam.jpg encryptz<span
style="color: #000000; font-weight: bold;">@</span>pthree.org:<span
style="color: #000000; font-weight: bold;">/</span>var<span
style="color: #000000; font-weight: bold;">/</span>www<span
style="color: #000000; font-weight: bold;">/</span>wp-content<span
style="color: #000000; font-weight: bold;">/</span>uploads<span
style="color: #000000; font-weight: bold;">/</span><br
/> &nbsp; &nbsp; <span
style="color: #c20cb9; font-weight: bold;">sleep</span> <span
style="color: #000000;">30</span><br
/> <span
style="color: #000000; font-weight: bold;">done</span></div></td></tr></tbody></table></div><p>The JavaScript to reload the image was just as easy:</p><div
class="codecolorer-container javascript twitlight" 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="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #339933;">&amp;</span>lt<span
style="color: #339933;">;</span>script type<span
style="color: #339933;">=</span><span
style="color: #3366CC;">&quot;text/javascript&quot;</span><span
style="color: #339933;">&amp;</span>gt<span
style="color: #339933;">;</span><br
/> refreshImage <span
style="color: #339933;">=</span> <span
style="color: #003366; font-weight: bold;">function</span><span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span><br
/> <span
style="color: #009900;">&#123;</span><br
/> &nbsp; &nbsp; img <span
style="color: #339933;">=</span> document.<span
style="color: #660066;">getElementById</span><span
style="color: #009900;">&#40;</span><span
style="color: #3366CC;">&quot;desktopcam&quot;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> &nbsp; &nbsp; img.<span
style="color: #660066;">src</span> <span
style="color: #339933;">=</span> <span
style="color: #3366CC;">&quot;http://www.pthree.org/wp-content/uploads/DesktopCam.jpg?rand=&quot;</span> &nbsp; <span
style="color: #339933;">+</span> Math.<span
style="color: #660066;">random</span><span
style="color: #009900;">&#40;</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> <span
style="color: #009900;">&#125;</span><br
/> <span
style="color: #339933;">&amp;</span>lt<span
style="color: #339933;">;/</span>script<span
style="color: #339933;">&amp;</span>gt<span
style="color: #339933;">;</span><br
/> <span
style="color: #339933;">&amp;</span>lt<span
style="color: #339933;">;</span>script type<span
style="color: #339933;">=</span><span
style="color: #3366CC;">&quot;text/javascript&quot;</span><span
style="color: #339933;">&amp;</span>gt<span
style="color: #339933;">;</span><br
/> <span
style="color: #339933;">&amp;</span>lt<span
style="color: #339933;">;!--</span><br
/> window.<span
style="color: #660066;">setInterval</span><span
style="color: #009900;">&#40;</span>refreshImage<span
style="color: #339933;">,</span> <span
style="color: #CC0000;">30</span><span
style="color: #339933;">*</span><span
style="color: #CC0000;">1000</span><span
style="color: #009900;">&#41;</span><span
style="color: #339933;">;</span><br
/> <span
style="color: #006600; font-style: italic;">//--&amp;gt;</span><br
/> <span
style="color: #339933;">&amp;</span>lt<span
style="color: #339933;">;/</span>script<span
style="color: #339933;">&amp;</span>gt<span
style="color: #339933;">;</span></div></td></tr></tbody></table></div><p>The HTML in the post was even easier:</p><div
class="codecolorer-container html4strict twitlight" 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="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color: #ddbb00;">&amp;lt;</span>img id=&quot;desktopcam&quot; src=&quot;http://www.pthree.org/wp-content/uploads/DesktopCam.jpg&quot; alt=&quot;Desktop Cam&quot; /<span
style="color: #ddbb00;">&amp;gt;</span></div></td></tr></tbody></table></div><p>That&#8217;s it!  Probably what kept me hung up the most was getting WordPress to play nicely with inline JavaScript.  After a bit of searching and digging around though, I found the trick to getting JavaScript to work.</p><p>Anyway, there you go.  Fairly simple code, easy to implement and low overhead.</p> ]]></content:encoded> <wfw:commentRss>http://pthree.org/2006/11/27/new-pthree-feature-desktop-cam/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)

Served from: pthree.org @ 2010-09-02 23:30:50 -->