#!/usr/bin/expect -- ## This script is written to change password simultaneuously on all UNIX/Linux machine. ## So that the user don't have to change the password on every Linux machine in the CARG LAB. ## The name of the file must be passwd and it must be replaced with the original passwd ## file that comes with the normal Linux/Unix distribution. This is to make the procedure transparent to ## normal user. ## Also the client should be NFS Client and should have NFS server /etc mounted on it. So the password will be changed ## to the NFS Server in a Global Database. ## So the next time user login from any machine will be actually authenticated from the NFS Server. # set default variables set login "rlogin" set host "cargl2.ee.twsu.edu" set program "passwd" set user [exec whoami] set timeout 1000000 set prompt "(%|\\\$) " stty -echo send_user "1-old password: " expect_user -re "(.*)\n" send_user "\n" set oldpassword $expect_out(1,string) send_user "new password: " expect_user -re "(.*)\n" send_user "\n" set newpassword $expect_out(1,string) send_user "retype new password: " expect_user -re "(.*)\n" set newpassword2 $expect_out(1,string) send_user "\n" stty echo trap exit SIGINT if ![ string match $newpassword $newpassword2] { send_user "missmatch - password unchanged\n" exit } set pid [spawn rlogin $host -l $user] set logged_in 0 set timeout 30 for {} 1 {} { expect "Password*" { send "$oldpassword\r" } expect "timeout" { send_user "could not logged in\r" exec kill $pid expect eof break close exit } expect -re "incorrect|invalid" { send_user "bad password or login" exec kill $pid expect eof break } expect "$*" { set logged_in 1 break } } # for loop closes # if (!$logged_in) { # wait # continue # } send "$program\r" expct "UNIX password*" { send "$oldpassword\r" expect "Sorry|failure" { send_user "Old password is bad" continue } "password:" } -re "(n|N)ew password:" send "$newpassword\r" expect -re "not changed|unchanged" { send "new password is bad" continue } -re "(password|verification|verify|again):.*" send "$newpassword\r" expect -re "(not changed|incorrect) .*" { send "password is bad" continue } -re "$prompt" send_user "\n" close wait } send_user "Old password is bad" continue } "password:" } -re "(n|N)ew password:" send "$newpassword\r" expect -re "not changed|unchanged" { send "new password is bad" continue } -re "(password|verification|verify|again):.*" send "$newpassword\r" expect -re "(not changed|incorrect) .*" { send "password is bad" continue } -re "$prompt" send_user "\n" close wait }