problem with expect eof

hi guys

i have such simple script, which i'm executing on AIX 5.3

#!/usr/local/bin/expect

spawn passwd exptest
set password 123
expect "*password:*"
send "$password\r"
expect "*password again:*"
send "$password\r"
expect eof

the output is following:

spawn passwd exptest
sh: /usr/local/bin/stty:  not found.
Changing password for "exptest"
exptest's New password:
Enter the new password again:

and that's it. script hangs at this place and i have no control with shell...

what could be the problem?

Basically, your script seems correct, but I have no expect installed on AIX currently, so I can test it. Um, which version of expect is used ? What is the location of stty ? I have it under /usr/bin/stty, do a "which stty" and you can try to edit the $PATH and test again ?

I would wrote your script like :

#!/usr/local/bin/expect

spawn passwd exptest
set password some-pass
expect "*password:*"
sleep 1
send "$password\r"
expect "*password again:*"
sleep 1
send "$password\r"
expect eof

i have 5.43 version of expect downloaded from here AIX PDSLIB Package: expect

i also have stty located under /usr/bin, and $PATH is OK. i created symbolic link /usr/local/bin/stty to /usr/bin/stty, so i dont have warning about stty, but result of the script is the same.

this variant doesn't work either... script hangs

By default the timeout is small number, and if the machine is hanging or responding slowly, you will loose the terminal created from "spawn". Try to do "set timeout -1" in the beginnig of the script and see if it helps. Use "-d" flag for debug and see what's going on.

ok, now the script is followng

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

set timeout -1
set password 123
spawn passwd exptest
expect "*password:*"
sleep 1
send "$password\r"
expect "*password again:*"
sleep 1
send "$password\r"
expect eof

and again i cant control the shell

here is debug output, looks fine as for me :slight_smile:

# ./expp
expect version 5.43.0
argv[0] = /usr/local/bin/expect  argv[1] = -d  argv[2] = ./expp
set argc 0
set argv0 "./expp"
set argv ""
executing commands from command file ./expp
spawn passwd exptest
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {17710}

expect: does "" (spawn_id exp4) match glob pattern "*password:*"? no
Changing password for "exptest"
exptest's New password:
expect: does "Changing password for "exptest"\r\nexptest's New password: " (spawn_id exp4) match glob pattern "*password:*"? yes
expect: set expect_out(0,string) "Changing password for "exptest"\r\nexptest's New password: "
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "Changing password for "exptest"\r\nexptest's New password: "
send: sending "123\r" to { exp4 }

expect: does "" (spawn_id exp4) match glob pattern "*password again:*"? no

Enter the new pa
expect: does "\r\nEnter the new pa" (spawn_id exp4) match glob pattern "*password again:*"? no
ssword again:
expect: does "\r\nEnter the new password again:" (spawn_id exp4) match glob pattern "*password again:*"? yes
expect: set expect_out(0,string) "\r\nEnter the new password again:"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "\r\nEnter the new password again:"
send: sending "123\r" to { exp4 }

expect: read eof
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "\r\n"

maybe something wrong with my AIX...