<?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>jDictionary Blog &#187; Programming</title>
	<atom:link href="http://blog.jdictionary.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jdictionary.com</link>
	<description>Rick Noelle&#039;s Japanese language study blog.</description>
	<lastBuildDate>Tue, 15 Mar 2011 21:46:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Perl and Python</title>
		<link>http://blog.jdictionary.com/2008/08/perl-and-python/</link>
		<comments>http://blog.jdictionary.com/2008/08/perl-and-python/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 19:06:28 +0000</pubDate>
		<dc:creator>Rick Noelle</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.jdictionary.com/?p=12</guid>
		<description><![CDATA[Today I converted a simple Perl script of mine to Python.  It was pretty easy to do and a good introduction to Python.  The script is meant to run on Linux.  It prompts the user for a command and then runs the command on a list of remote servers and displays the output (using ssh).  [...]]]></description>
			<content:encoded><![CDATA[<p>Today I converted a simple Perl script of mine to Python.  It was pretty easy to do and a good introduction to Python.  The script is meant to run on Linux.  It prompts the user for a command and then runs the command on a list of remote servers and displays the output (using ssh).  For example, if you have 3 remote servers and want to run "uptime" on all of them, it would be easy to do with this script.  I thought I would show the source for both here.  I personally think the Python version looks cleaner and it is easier to read.  I am intrigued by Python because it is a scripted language like Perl but also an object oriented language like Java.  Since I have developed with both Perl and Java, I thought it might be a good match for my skills.  The fact that many of the utilities that come with Red Hat Linux are written in Python is encouraging too.  So anyhow, here they are.</p>
<p>Perl Version</p>
<pre class="brush: perl; title: ; notranslate">
#!/usr/bin/perl
use strict;
use warnings;
use Term::ANSIColor qw(:constants);

print &quot;Command to run remotely: &quot;;
my $cmd = &amp;lt;STDIN&amp;gt;;
chomp($cmd);

my @servers = ('server1','server2','server3');

foreach my $server (@servers)
{
  print BOLD . &quot;$server\$ $cmd\n&quot; . RESET;
  my $out = qx(ssh $server '$cmd');
  print GREEN . $out . RESET;
  print &quot;\n&quot;;
}
</pre>
<p>Python Version</p>
<pre class="brush: python; title: ; notranslate">
#!/usr/bin/env python

import os

command = raw_input(&quot;Command to run remotely: &quot;)

servers = [&quot;server1&quot;,&quot;server2&quot;,&quot;server3&quot;]

for server in servers:
  os.system('tput bold')
  print server + &quot;$ &quot; + command
  os.system('tput sgr0')
  os.system('tput setf 2')
  os.system(&quot;ssh &quot; + server + &quot; &quot; + command)
  os.system('tput sgr0')&lt;/code&gt;

print
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.jdictionary.com/2008/08/perl-and-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

