<?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>Ohjeah! &#187; scripts</title>
	<atom:link href="http://www.ohjeah.net/tag/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ohjeah.net</link>
	<description>The writings of JRO...</description>
	<lastBuildDate>Wed, 09 Jun 2010 20:58:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Linux Update Password Script</title>
		<link>http://www.ohjeah.net/2009/03/04/linux-update-password-script/</link>
		<comments>http://www.ohjeah.net/2009/03/04/linux-update-password-script/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 15:51:47 +0000</pubDate>
		<dc:creator>jro</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://www.ohjeah.net/?p=199</guid>
		<description><![CDATA[In my last post I showed a good example for using expect in a script.  Here is another good example I use for updating local user passwords across a group of servers without using ssh keys.  This assumes the user you are resetting can ssh to the host and the old password is the same [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post I showed a good example for using expect in a script.  Here is another good example I use for updating local user passwords across a group of servers without using ssh keys.  This assumes the user you are resetting can ssh to the host and the old password is the same on all hosts.<span id="more-199"></span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;"># $Id: password_change.sh 6 2009-03-09 18:57:02Z jaredo $</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Copyright (c) 2009 Jared Orzechowski &amp;lt;jaredo at ameritech dot net&amp;gt;</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Description:  This script will ssh to servers and change the specified</span>
<span style="color: #666666; font-style: italic;"># users password (assuming user can ssh).  Requires expect package.</span>
&nbsp;
<span style="color: #007800;">USER</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #007800;">OLDPW</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #007800;">NEWPW</span>=<span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> resetpw<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
          <span style="color: #7a0874; font-weight: bold;">echo</span>
          <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Attempting to reset password for <span style="color: #007800;">$USER</span> on host $1..&quot;</span>
&nbsp;
              <span style="color: #007800;">CMD</span>=<span style="color: #ff0000;">&quot;ssh -l root $1 passwd <span style="color: #007800;">$USER</span>&quot;</span>
              expect <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;
              match_max 100000
              spawn <span style="color: #007800;">$CMD</span>
&nbsp;
              expect {
                <span style="color: #000099; font-weight: bold;">\&quot;</span>Are you sure you want to continue connecting (yes/no)?<span style="color: #000099; font-weight: bold;">\&quot;</span> {
                send <span style="color: #000099; font-weight: bold;">\&quot;</span>yes<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\&quot;</span>
                exp_continue
                }
                <span style="color: #000099; font-weight: bold;">\&quot;</span>s password:<span style="color: #000099; font-weight: bold;">\&quot;</span> {
                send <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">$OLDPW</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\&quot;</span>
                exp_continue
                }
                <span style="color: #000099; font-weight: bold;">\&quot;</span>UNIX password:<span style="color: #000099; font-weight: bold;">\&quot;</span> {
                send <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">$NEWPW</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\&quot;</span>
                exp_continue
                expect -re <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">$USER</span>*<span style="color: #000099; font-weight: bold;">\&quot;</span>
                }
              }
              &quot;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
          <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Missing hostname..&quot;</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Syntax: resetpw hostname</span>
<span style="color: #666666; font-style: italic;">#Example:</span>
resetpw myserver1
resetpw myserver2
resetpw myserver3
resetpw myserver4</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.ohjeah.net/2009/03/04/linux-update-password-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
