SSH: $ssh->cmd("passwd") does not work properly

From: Quackie (minh_quoc_at_yahoo.com)
Date: 05/06/03

  • Next message: bjoeboo: "clientless windowsbased sftp / ssh server?"
    Date: 5 May 2003 17:35:52 -0700
    
    

    I devenlop a Perl script that automately log in to remote server using
    SSH2 and execute series of commands.

    My Perl client runs on Windows 2000 using Net::SSH:W32Perl package.
    My SSH server is OpenSSH3.6.1 runs on Solaris 8.

    Everything works fine. I can login to remote server with password
    authentication, public key authentication ... and runs few commands
    such as "ls", "whoami" ... However, for the command that require
    interaction from the user input such as "su" or "passwd", I have the
    problem.
    This is part of my script

    use strict;
    use Net::SSH::W32Perl;

    my $ssh = Net::SSH::W32Perl->new($host, debug => 1);
    $ssh->login("username", "password");

    $ssh->register_handler("stderr", sub {
        my($channel, $buffer) = @_;
        my $str = $buffer->bytes;
        
        # debug
        print "str received is ", $str;

        if ($str eq "Enter login password: ") {
            $channel->send_data($old_password);
        }

        elsif ($str eq "New password: ") {
            $channel->send_data($new_password);
        }

        elsif ($str eq "Retype new password: ") {
            $channel->send_data($new_password);
        }
    });

    ## After registering the handler, we run the command.

    $ssh->cmd('passwd');

    After executing this script, the str received is not one of those
    expected prompts (New password , ....), but I got the message "passwd:
    Permission denied" for the str.

    Tried it with "su" command instead of "passwd" and I got the message
    "su:Sorry". It seems to me that the server does not stop at the
    command prompt and send it back, but instead go all the way to the
    user prompt and send back the error message of that command.

    Anyone here has any clue about this?

    Thanks in advance


  • Next message: bjoeboo: "clientless windowsbased sftp / ssh server?"

    Relevant Pages

    • Re: Installing TDK 4.0.4 trial with Tcl 8.5.1...
      ... Locate an ActiveTcl 8.4.9.1+ installation for use by the Tcl Dev Kit demos. ... Then the TDK installer continues with: ... remote server cannot handle this command ...
      (comp.lang.tcl)
    • Installing TDK 4.0.4 trial with Tcl 8.5.1...
      ... Locate an ActiveTcl 8.4.9.1+ installation for use by the Tcl Dev Kit demos. ... remote server cannot handle this command ...
      (comp.lang.tcl)
    • Re: FTP an Access MDB
      ... Open an FTP session manually so that you can troubleshoot your FTP script by ... The default is to overwrite existing files, but your put command ... remote server with the PWD command. ...
      (microsoft.public.access.forms)
    • Re: Installing TDK 4.0.4 trial with Tcl 8.5.1...
      ... Locate an ActiveTcl 8.4.9.1+ installation for use by the Tcl Dev Kit demos. ... No bwidget package found in selected ActiveTcl ... remote server cannot handle this command ...
      (comp.lang.tcl)
    • Re: Ive thought better of Linux
      ... > an outgoing queue that gets delivered if the remote server is ... # This program is free software; ... See the GNU General Public License for more details. ... read command arguments ...
      (comp.lang.lisp)