#!/usr/bin/expect -f # # passwd sometimes doesn't respond fast enough and you can # actually type in the first couple characters of your # password before "passwd" is actually ready to receive! # so I 'sleep .1' at various times in the script to help # this along. set timeout 20 spawn /bin/su [lindex $argv 0] -c "/bin/passwd [lindex $argv 0]" exp_internal 1 match_max 100000 expect { "Unknown login:" { exit 1 } timeout { exit 2 } "Password:" } sleep .1 send "[lindex $argv 1]\r" sleep .1 expect { "unknown user" { exit 3 } "Sorry" { exit 4 } timeout { exit 2 } "Old password:" } sleep .1 send "[lindex $argv 1]\r" sleep .1 expect "New password:" sleep .1 send "[lindex $argv 2]\r" sleep .1 expect { "Please enter a longer password." { exit 5 } "all-lower case password." { exit 6 } timeout { exit 2 } "ew password:" } sleep .1 send "[lindex $argv 2]\r" sleep .1 expect eof