title: Problem with an expect script
body: <p>I'm trying to create a script to update a password in a
  non-interactive way. It's working on my laptop but fails on my server.
  Both are running the same configuration, using Etch.</p>
  
  <p>This is the script:</p>
  
  <pre><code>#!/usr/bin/expect -f
  # Change user passwd
  set timeout 30
  strace 4
  set password [lindex $argv 1]
  set old_password [lindex $argv 2]
  
  spawn passwd [lindex $argv 0]
  sleep 1
  expect "(current) UNIX password: $"
  send "$old_password\r"
  expect "Enter new UNIX password: $"
  send "$password\r"
  expect "Retype new UNIX password: $"
  send "$password\r"
  expect eof
  </code></pre>
  
  <p>On the server the output looks like this:</p>
  
  <pre><code>myuser@server:~$  /home/myuser/adm/chpasswd myuser NewPasswd OldPasswd
   2    lindex $argv 0
   1  set username [lindex $argv 0]
   2    lindex $argv 1
   1  set password [lindex $argv 1]
   2    lindex $argv 2
   1  set old_password [lindex $argv 2]
   1  spawn passwd $username
  spawn passwd myuser
   1  sleep 1
   1  expect "(current) UNIX password: $"
  Changing password for myuser
  (current) UNIX password:  1  send "$old_password\r"
   1  expect "Enter new UNIX password: $"
  OldPasswd
  Enter new UNIX password:  1  send "$password\r"
   1  expect "Retype new UNIX password: $"
  NewPasswd
   1  send "$password\r"
   1  expect eof
  Retype new UNIX password:  1  exit 0
  </code></pre>
  
  <p>So is not working, as the couple expect-send seems unsync.</p>
  
  <p>But strangely enough, on my laptop it works:</p>
  
  <pre><code>test@mars:/home/test/adm$ ./chpasswd test NewPasswd OldPasswd
   2    lindex $argv 1
   1  set password [lindex $argv 1]
   2    lindex $argv 2
   1  set old_password [lindex $argv 2]
   2    lindex $argv 0
   1  spawn passwd [lindex $argv 0]
  spawn passwd test
   1  sleep 1
   1  expect "(current) UNIX password: $"
  Changing password for test
  (current) UNIX password:  1  send "$old_password\r"
   1  expect "Enter new UNIX password: $"
  OldPasswd
  Enter new UNIX password:  1  send "$password\r"
   1  expect "Retype new UNIX password: $"
  NewPasswd
  Retype new UNIX password:  1  send "$password\r"
   1  expect eof
  NewPasswd
  passwd: password updated successfully
   1  exit 0
  </code></pre>
  
  <p>Any ideas why it's going wrong on the server ?
  Thanks</p>