I am trying to use expect to generate users ' password
#!/usr/bin/expect -d
set password [lindex $argv 1]
spawn passwd [lindex $argv 0]
expect -re ".*password:"
send "$password\r"
expect -re ".*password:"
send "$password\r"
expect eof
Unfortunately, sometimes (in fact very often) it doesn 't work
As if expect is waiting for a blank line after the "first password" is entered
I don t know why. Then it seems to be totally desynchronise
Here is the output of the debugging mode
#./pass1 steph steph
expect version 5.43.0
argv[0] = /usr/bin/expect argv[1] = -d argv[2] = ./pass1 argv[3] = steph arg v[4] = steph
set argc 2
set argv0 "./pass1"
set argv "steph steph"
executing commands from command file ./pass1
spawn passwd steph
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {31841}
expect: does "" (spawn_id exp6) match regular _expression ".*password:"? no
Enter new UNIX password:
expect: does "Enter new UNIX password: " (spawn_id exp6) match regular _expressio n ".*password:"? yes
expect: set expect_out(0,string) "Enter new UNIX password:"
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "Enter new UNIX password:"
send: sending "steph\r" to { exp6 }
expect: does " " (spawn_id exp6) match regular _expression ".*password:"? no
steph
expect: does " steph\r\n" (spawn_id exp6) match regular _expression ".*password:" ? no
expect: timed out
send: sending "steph\r" to { exp6 }
Retype new UNIX password: expect: timed out
write() failed to write anything - will sleep(1) and retry...
Découvrez un nouveau moyen de poser toutes vos questions quelque soit le sujet ! Yahoo! Questions/Réponses pour partager vos connaissances, vos opinions et vos expériences. Cliquez ici.