Class AutomateIt::AccountManager::PasswdExpect
In: lib/automateit/account_manager/passwd_expect.rb
Parent: ::AutomateIt::AccountManager::BaseDriver

AccountManager::PasswdExpect

An AccountManager driver for the passwd command found on Unix-like systems using the expect program as a wrapper because the Ruby PTY implementation is unreliable.

Methods

passwd  

Public Instance methods

See AccountManager#passwd

[Source]

# File lib/automateit/account_manager/passwd_expect.rb, line 15
  def passwd(user, password, opts={})
    _passwd_helper(user, password, opts) do |user, password, opts|
      log.silence(Logger::WARN) do
        interpreter.mktemp do |filename|
          # Script derived from /usr/share/doc/expect/examples/autopasswd
          interpreter.render(:text => "set password \"\#{password}\"\nspawn passwd \"\#{user}\"\nexpect \"assword:\"\nsleep 0.1\nsend \"$password\\\\r\"\nexpect \"assword:\"\nsleep 0.1\nsend \"$password\\\\r\"\nexpect eof\n", :to => filename)

          cmd = "expect #{filename}"
          cmd << " > /dev/null" if opts[:quiet]
          return(interpreter.sh cmd)
        end
      end
    end
  end

[Validate]