<?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>Nicholas Pike &#187; work</title>
	<atom:link href="http://blog.npike.net/category/work/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.npike.net</link>
	<description>Like nailing jelly to a wall...</description>
	<lastBuildDate>Tue, 20 Jul 2010 05:45:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>My tech-mojo has gone on vacation.</title>
		<link>http://blog.npike.net/2007/10/30/my-tech-mojo-has-gone-on-vacation/</link>
		<comments>http://blog.npike.net/2007/10/30/my-tech-mojo-has-gone-on-vacation/#comments</comments>
		<pubDate>Tue, 30 Oct 2007 18:50:20 +0000</pubDate>
		<dc:creator>npike</dc:creator>
				<category><![CDATA[macbook]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[xbox]]></category>

		<guid isPermaLink="false">http://blog.npike.net/2007/10/30/my-tech-mojo-has-gone-on-vacation/</guid>
		<description><![CDATA[&#8230; and with it, took my Xbox 360 and my laptop.
More or less my Xbox has decided to start red ringing and working intermittently &#8211; it will soon be shipped back to Microsoft in a coffin if it doesn&#8217;t straighten its act out.
Last night I tried to install my shiny new copy of Leopard retail, [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; and with it, took my Xbox 360 and my laptop.</p>
<p>More or less my Xbox has decided to start red ringing and working intermittently &#8211; it will soon be shipped back to Microsoft in a coffin if it doesn&#8217;t straighten its act out.</p>
<p>Last night I tried to install my shiny new copy of Leopard retail, only to discover that my Macbook dvd drive refuses to read dvd&#8217;s 19 out of 20 times.   I really don&#8217;t want to bring that to the Apple store, because it will definitely result in my trusty Macbook being shipped to Apple for repair &#8211; which could take awhile.</p>
<p>In the mean time I will just have to live vicariously through upgrading other laptops to Leopard.</p>
<p><strong>Quick Rant</strong></p>
<p>I HATE it when people use the urinal in the mens lavatory and feel its okay to leave without washing their hands.  I mean, come on people!  I takes <strong>15 seconds</strong> to wash your hands, and another <strong>15 seconds</strong> to dry them.  Heck, Thomson is even <em>paying</em> for you to wash your hands &#8211; for the sake of everyone else that has to touch the door handle to leave the lavatory <strong>Please wash your hands!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.npike.net/2007/10/30/my-tech-mojo-has-gone-on-vacation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Remotely executing shell commands in a bash script with ssh and expect</title>
		<link>http://blog.npike.net/2007/10/02/remotely-executing-shell-commands-in-a-bash-script-with-ssh-and-expect/</link>
		<comments>http://blog.npike.net/2007/10/02/remotely-executing-shell-commands-in-a-bash-script-with-ssh-and-expect/#comments</comments>
		<pubDate>Tue, 02 Oct 2007 17:18:08 +0000</pubDate>
		<dc:creator>npike</dc:creator>
				<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.npike.net/2007/10/02/remotely-executing-shell-commands-in-a-bash-script-with-ssh-and-expect/</guid>
		<description><![CDATA[So an on going project of mine at work had been to create a bash shell script, that could be run at regular intervals, that would check that all servers in an environment were identical compared to their &#8220;master server&#8221;.
This would require comparing each server against its master with a specific set of criteria:

Network Filesystem [...]]]></description>
			<content:encoded><![CDATA[<p>So an on going project of mine at work had been to create a bash shell script, that could be run at regular intervals, that would check that all servers in an environment were identical compared to their &#8220;master server&#8221;.</p>
<p>This would require comparing each server against its master with a specific set of criteria:</p>
<ul>
<li>Network Filesystem Mounts</li>
<li>User accounts</li>
<li>Groups</li>
<li>Group ID&#8217;s and User IDs</li>
</ul>
<p>My approach was simple, for each criteria use a set of commands to retrieve the necessary information, and save it to a text file in a sorted manner.   <em>Then</em> compare that against a file generated in the same manner for the master server in that environment.</p>
<p>This is all fine and peachy, until you actually want to send these commands to several servers spread out across a network, without the need for human interaction.</p>
<p>The method of sending commands and retrieving their output was an SSH connection to each machine, but unfortunately you can&#8217;t send your SSH password on the command line.  So to fix this hurdle, I used the expect binary, which basically watched standard output for a string, and sends your response.</p>
<p>Searches on the interwebs came up with sparse results on this matter, so below is my contribution so that hopefully a fellow geek won&#8217;t have as much non-luck as I with Google.</p>
<p><strong>linux_ssh.expect</strong></p>
<div class="codesnip-container" >#!/usr/bin/expect<br />
###<br />
# 2007 &#8211; Nicholas Pike<br />
#<br />
# This script takes 4 parameters, and will execute a command (or set of commands) on a remote server.<br />
# hostname<br />
# password<br />
# username<br />
# command<br />
#<br />
###<br />
set hostname [lindex $argv 0]<br />
set password [lindex $argv 1]<br />
set username [lindex $argv 2]<br />
set command [lindex $argv 3]<br />
spawn ssh $username@$hostname $command<br />
expect &#8220;password: &#8221;<br />
send &#8220;$password\r&#8221;<br />
send &#8212; &#8220;\r&#8221;<br />
expect eof</div>
<p>From within a bash script, you can call this file with the expect binary like so:</p>
<div class="codesnip-container" >#runRemoteCommand<br />
# runRemoteCommand takes 3 parameters (See below).  This will run a command (or series of commands) on<br />
# all machines listed in $BOX_LIST for the current environment specified in run()<br />
# The output of these commands will be written to a file located:<br />
#     box_compare/commandLabel/environment/[nameofserver]<br />
# After the polling is complete, the output files of the slave servers are diff&#8217;d against the<br />
# master servers output.<br />
# The results are appended to the text report for this environment.<br />
#<br />
#  runRemoteCommand &#8220;helloWorld&#8221; &#8220;Hello World&#8221; &#8220;echo \&#8221;hello world\&#8221;; ls&#8221;<br />
#<br />
# first parameter is command label<br />
# second parameter is criteria name<br />
# third parameter is command<br />
#<br />
runRemoteCommand() {<br />
mkdir $PATH_COMPARE/temp/$1<br />
mkdir $PATH_COMPARE/temp/$1/$ENVIRONMENT<br />
COMMAND=$3<br />
# run the remtoe command for each server in the box list for this environment<br />
for server in `echo $BOX_LIST`<br />
do<br />
EXPECT_COMMAND=&#8221;"$COMMAND&#8221;"<br />
expect -f linux_ssh.exp $server $PASSWORD $USERNAME &#8220;$EXPECT_COMMAND&#8221;  &gt; $PATH_COMPARE/temp/$1/$ENVIRONMENT/$server<br />
done<br />
}</div>
<p>The important line of course being:</p>
<div class="codesnip-container" >expect -f linux_ssh.exp $server $PASSWORD $USERNAME &#8220;$EXPECT_COMMAND&#8221;  &gt; $PATH_COMPARE/temp/$1/$ENVIRONMENT/$server</div>
<p><strong>Ta-da!</strong></p>
<p>So there ya go, a quick and &#8220;easy&#8221; way to send shell commands via SSH in a bash script to other *nix based computers.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.npike.net/2007/10/02/remotely-executing-shell-commands-in-a-bash-script-with-ssh-and-expect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
