title: Expect script to change password using ssh
body: <p>Can anyone help what is the problem with below script? It says password changed successfully, but password remains old password. I am running this script to change checkpoint SPLAT firewall expert password, which directly logins to expert mode using ssh.</p>
  
  <pre><code>#!/usr/bin/expect
  set username admin
  set oldpass sam$$$
  set newpass abc.123
  
  spawn ssh -l $username 192.168.1.10
  
  expect "assword:"
  send "$oldpass\r"
  expect "# "
  sleep 1
  send "passwd\r"
  expect "Enter new expert password:"
  send "$newpass\r"
  expect "Enter new expert password (again):"
  send "$newpass\r"
  expect eof"
  expect "# "
  send "exit\n"
  
  
  [admin@localhost ~]$ ./test.sh
  spawn ssh -l admin 192.168.1.10
  admin@192.168.1.10's password:
  Last login: Thu Oct 30 18:41:52 2014 from 192.168.1.5
  [Expert@cpmodule]# passwd
  Enter new expert password:
  Enter new expert password (again):
  Expert password has been changed
  </code></pre>