On Fri, Feb 09, 2001 at 10:16:12AM +1100, Simon Bryan wrote:

> looking for some kind person who knows about these things to send me a 
> short script that would call 'passwd' repeatedly from names in a file and 

When run as root, and given a username, `passwd' asks for the new
password twice.  Simply creating a text file with two lines, each with
the new password, doesn't work (`passwd' probably flushes the input
buffer after printing the prompt).  However, you could use `expect' to
do what you need.  Below is a working example (generated by autoexpect
and slightly modified by me).  Run it like this:

    for i in "user1 user2 user3"; do ./passwd.exp $i; done

If you want to specify the new password on the command line, change
the text `abcd1234' to `[lrange $argv 1 1]' in both places.


Cheers,

John

----------------

#!/usr/bin/expect -f

set force_conservative 1  ;# set to 1 to force conservative mode even if
                          ;# script wasn't run conservatively originally
if {$force_conservative} {
        set send_slow {1 .1}
        proc send {ignore arg} {
                sleep .1
                exp_send -s -- $arg
        }
}

set timeout -1
spawn passwd [lrange $argv 0 0]
match_max 100000
expect "New UNIX password: "
# new password
send -- "abcd1234\r"
expect "Retype new UNIX password: "
# repeat new password
send -- "abcd1234\r"
expect eof


-- 
whois [EMAIL PROTECTED]

-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug

Reply via email to