exec expect
-- "$0" ${1+"$@"}
# passmass: change password on many machines
# Synopsis: passmass host1 host2 host3 ....
# Don Libes - March 11, 1991
# Description: Change passwords on the named machines.
# See passmass.man for further info.
send_user
"usage: $argv0 host1 host2 host3 . . .\n"
expect_before
-i $user_spawn_id \003 exit
proc badhost
{host emsg
} {
send_user
"\r\n\007password not changed on $host - $emsg\n\n"
if {0==[llength
$badhosts]} {
set badhosts
[concat
$badhosts $host]
send_user
"old password: "
set password
(old
) $expect_out(1,string
)
set password
(login
) $expect_out(1,string
)
send_user
"new password: "
set password
(new
) $expect_out(1,string
)
send_user
"retype new password: "
set password
(newcheck
) $expect_out(1,string
)
send_user
"login password: "
set password
(login
) $expect_out(1,string
)
send_user
"root password: "
set password
(old
) $expect_out(1,string
)
send_user
"new password: "
set password
(new
) $expect_out(1,string
)
send_user
"retype new password: "
set password
(newcheck
) $expect_out(1,string
)
if ![string match
$password(new
) $password(newcheck
)] {
send_user
"mismatch - password unchanged\n"
for {set i
0} {$i<$argc} {incr i
} {
set arg
[lindex
$argv $i]
set user
[lindex
$argv $i]
set prompt
[lindex
$argv $i]
set program
[lindex
$argv $i]
set timeout
[lindex
$argv $i]
if {[string match
$login "rlogin"]} {
set pid
[spawn
rlogin $host -l $user]
} elseif
{[string match
$login "slogin"]} {
set pid
[spawn slogin
$host -l $user]
} elseif
{[string match
$login "ssh"]} {
set pid
[spawn
ssh $host -l $user]
set pid
[spawn
telnet $host]
expect
-nocase -re "(login|username):.*" {
if ![info exists prompt
] {
if {[string match
$user "root"]} {
expect
-nocase "password*" {
send
"$password(login)\r"
badhost
$host "spawn failed"
badhost
$host "could not log in (or unrecognized prompt)"
} -re "incorrect|invalid" {
badhost
$host "bad password or login"
expect
-nocase "password:"
expect
-nocase -re "(old|existing login) password:.*" {
expect
-nocase "sorry*" {
badhost
$host "old password is bad?"
} -nocase -re "new password:" {
# got prompt, fall through
badhost
$host "could not recognize prompt for password"
expect
-re "not changed|unchanged" {
badhost
$host "new password is bad?"
} -nocase -re "(password|verification|verify|again):.*"
expect
-nocase -re "(not changed|incorrect|choose new).*" {
badhost
$host "password is bad?"
if {[llength
$badhosts]} {
send_user
"\nfailed to set password on $badhosts\n"