Solaris passwd script

Hello all,

Since Solaris passwd does not have --stdin option can you advise how to change the password for 30 users with a script. The password can be the same one. I`ve tried already echoing, xargs, cat and similar.

Thanks.

---------- Post updated at 04:04 AM ---------- Previous update was at 03:13 AM ----------

Done it, thanks to my colleagues for suggesting this :slight_smile:

One bash script with

#!/bin/bash
USERS="bob john carry"
for user in $USERS;
do
echo "Changing password for" $user
./chpass.exp $user
done

One expect script called ./chpass.exp

#!/usr/local/bin/expect -f

set force_conservative 0  ;# 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 username [lindex $argv 0]
set timeout -1
spawn passwd $username
match_max 100000
New Password: "
send -- "test1\r"
expect -exact "\r
Re-enter new Password: "
send -- "test1\r"
expect eof

And we`re golden.

1 Like