# problem with expect eof

**URL:** <https://community.unix.com/t/problem-with-expect-eof/175124>\
**Category:** AIX\
**Created:** [August 31, 2007, 11:44am UTC](https://community.unix.com/t/problem-with-expect-eof/175124 "2007-08-31T11:44:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zoom](https://community.unix.com/letter_avatar/zoom/32/6_449c533f586939b6e5f246632a46421f.png) [@zoom](https://community.unix.com/u/zoom)\
**Post date:** [August 31, 2007, 11:44am UTC](https://community.unix.com/t/problem-with-expect-eof/175124/1 "2007-08-31T11:44:40Z")

</div>

hi guys

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

```nohighlight
#!/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:

```nohighlight
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?

---

<div class="post-metadata">

**Author:** ![sysgate](https://community.unix.com/user_avatar/community.unix.com/sysgate/32/3504_2.png) [@sysgate](https://community.unix.com/u/sysgate)\
**Post date:** [September 3, 2007, 9:54am UTC](https://community.unix.com/t/problem-with-expect-eof/175124/2 "2007-09-03T09:54:05Z")

</div>

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 :

```nohighlight
#!/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

```

---

<div class="post-metadata">

**Author:** ![zoom](https://community.unix.com/letter_avatar/zoom/32/6_449c533f586939b6e5f246632a46421f.png) [@zoom](https://community.unix.com/u/zoom)\
**Post date:** [September 3, 2007, 10:15am UTC](https://community.unix.com/t/problem-with-expect-eof/175124/3 "2007-09-03T10:15:52Z")

</div>

> [@sysgate](#):
>
> 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 have 5.43 version of expect downloaded from here [AIX PDSLIB Package: expect](http://aixpdslib.seas.ucla.edu/packages/expect.html)

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.

> [@](#):
>
> I would wrote your script like :
> 
> ```plaintext
> #!/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
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![sysgate](https://community.unix.com/user_avatar/community.unix.com/sysgate/32/3504_2.png) [@sysgate](https://community.unix.com/u/sysgate)\
**Post date:** [September 4, 2007, 9:24am UTC](https://community.unix.com/t/problem-with-expect-eof/175124/4 "2007-09-04T09:24:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zoom](https://community.unix.com/letter_avatar/zoom/32/6_449c533f586939b6e5f246632a46421f.png) [@zoom](https://community.unix.com/u/zoom)\
**Post date:** [September 6, 2007, 6:12am UTC](https://community.unix.com/t/problem-with-expect-eof/175124/5 "2007-09-06T06:12:58Z")

</div>

ok, now the script is followng

```nohighlight
#!/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 🙂

```nohighlight
# ./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...
