Just to give you an idea, here's the script:<br><br><span style="color: rgb(51, 51, 255);">#!/usr/bin/python</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
import os</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">import sys</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">import pexpect</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">import getopt</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">import ConfigFile</span><br style="color: rgb(51, 51, 255);">
<br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">def changeUserPw(host, user, cur_pw, new_pw):</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
        log_file.write('Changing password of user ' + user + ' on host ' + host + '\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child=pexpect.spawn
('slogin ' + user + '@' + host)</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.expect('[Pp]assword:')</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">        child.send(cur_pw + '\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.expect('[#\$] ')</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">        child.send('passwd\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.expect('[Cc]urrent.*[pP]assword:')</span>
<br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.send(cur_pw + '\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.expect('[Nn]ew [Pp]assword:')
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.send(new_pw + '\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.expect
('[Nn]ew [Pp]assword:')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.send(new_pw + '\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
        child.expect('[#\$] ')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        log_file.write('password change successful\n')</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">        child.send('exit\n');</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.expect(pexpect.EOF)</span><br style="color: rgb(51, 51, 255);">
<br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">def changeRootPw(host, user, cur_pw, cur_root_pw, new_root_pw):</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
        log_file.write('Changing password of user root on host ' + host + '\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child=pexpect.spawn('slogin ' + user + '@' + host)
</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.expect('[Pp]assword:')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
        child.send(cur_pw + '\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.expect('[#\$] ')</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">        child.send('su -\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.expect('[Pp]assword:')</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">        child.send(cur_root_pw + '\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.expect('[#\$] ')</span><br style="color: rgb(51, 51, 255);">
<br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.send('passwd\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.expect('[Nn]ew [Pp]assword:')
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.send(new_root_pw + '\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.expect
('[Nn]ew [Pp]assword:')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.send(new_root_pw + '\n')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
        child.expect('[#\$] ')</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        log_file.write('password change successful\n')</span>
<br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.send('exit\n');           # exit from root shell</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
        child.expect('[#\$] ')</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        child.send('exit\n');           # exit from user shell</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">        child.expect(pexpect.EOF)</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">opts, args = getopt.getopt(sys.argv
[1:], "c:")</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">cfg_file_name = None</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">for o,a in opts:
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        if o == '-c':</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                cfg_file_name = a 
</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">if cfg_file_name == None:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
        print 'PwChange.py -c <config file name>'</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        sys.exit(0)</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">cfg_file=ConfigFile.ConfigFile(cfg_file_name, ':')</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">log_file_name = cfg_file.getVal('log_file')
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">if log_file_name == None or log_file_name == '':</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
        log_file = sys.stderr</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">else:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        log_file = open(log_file_name, 'w');
</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">groups = cfg_file.getVal('groups');</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
for group in groups.split():</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        pw_file_name = cfg_file.getVal(group + '.pw_file')</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">        if pw_file_name == None:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                print "No " + group + ".pw_file parameter in config file, exiting"
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                sys.exit(0)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        pw_file = open(pw_file_name, 'r');
</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        default_cur_pw = cfg_file.getVal(group + '.default_cur_pw');</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">        default_new_pw = cfg_file.getVal(group + '.default_new_pw');</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        default_cur_root_pw = cfg_file.getVal(group + '.default_cur_root_pw');
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        default_new_root_pw = cfg_file.getVal(group + '.default_new_root_pw');</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">        for ln in pw_file:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                if ln[0] == '#':</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">                        continue</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                if ln.strip() == '' or ln.strip() == None:</span>
<br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                        continue</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                fields = ln[0:-1].split(':')
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                if len(fields) == 4:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                        if fields[2] == 'default':
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                if default_cur_pw != None:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
                                        fields[2] = default_cur_pw</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                else:</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">                                        print "default specified in password file, but no default_cur_pw specified in config file, bye!"</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">                                        sys.exit(0)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                        if fields[3] == 'default':
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                if fields[3] != None:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                        fields[3] = default_new_pw
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                else:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                        print "default specified in password file, but no default_new_pw specified in config file, bye!"
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                        sys.exit(0)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                        changeUserPw(fields[0], fields[1], fields[2], fields[3])
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                elif len(fields) == 5:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                        if fields[2] == 'default':
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                if default_cur_pw != None:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
                                        fields[2] = default_cur_pw</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                else:</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">                                        print "default specified in password file, but no default_cur_pw specified in config file, bye!"</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">                                        sys.exit(0)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                        if fields[3] == 'default':
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                if default_cur_root_pw != None:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
                                        fields[3] = default_cur_root_pw</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                else:</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">                                        print "default specified in password file, but no default_cur_root_pw specified in config file, bye!"</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">                                        sys.exit(0)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                        if fields[4] == 'default':
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                if default_new_root_pw != None:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">
                                        fields[4] = default_new_root_pw</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                                else:</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">                                        print "default specified in password file, but no default_new_root_pw specified in config file, bye!"</span><br style="color: rgb(51, 51, 255);">
<span style="color: rgb(51, 51, 255);">                                        sys.exit(0)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">                        changeRootPw(fields[0], fields[1], fields[2], fields[3], fields[4])
</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">        pw_file.close()<br><br><span style="color: rgb(0, 0, 0);">What you're trying to do should be considerably shorter.<br><br>Thanks,
<br>Larry Barber<br style="color: rgb(51, 51, 255);"></span></span><br><br><div><span class="gmail_quote">On 8/23/07, <b class="gmail_sendername">Larry Barber</b> <<a href="mailto:lebarber@gmail.com">lebarber@gmail.com
</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I used Python and pexpect to write a script that changed the passwords on all my machines. A script to do what you are asking for should be quite straight forward using those tools.
<br><br>Thanks,<br><span class="sg">Larry Barber</span><div><span class="e" id="q_11493f1815f7d858_2"><br><br><div>
<span class="gmail_quote">On 8/23/07, <b class="gmail_sendername">Dan Simoes</b> <<a href="mailto:dan.simoes@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">dan.simoes@gmail.com</a>> wrote:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I know how to monitor the service availablity on port 22.<br>I'm wondering if anyone has actually made a script that connects, logs in, writes a file (say with scp) and only then returns a green status.<br>We got burned with an ssh keys problem so I have to deploy something like this.
<br>
</blockquote></div><br>
</span></div></blockquote></div><br>