veeruch has asked for the wisdom of the Perl Monks concerning the following question:

while i run this script with debug =>1;
use Net::SSH::W32Perl; my $ssh = Net::SSH::W32Perl->new($host,debug=>1); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("ls -lrt");

iam putting last three lines of code
indamaaaf31786: Entering interactive session.
indamaaaf31786: Sending command: ls -lrt
indamaaaf31786: Requesting service exec on channel 1.
indamaaaf31786: channel 1: open confirm rwindow 0 rmax 31234
After this system is busy no output

2006-07-04 Retitled by planetscape, as per Monastery guidelines

( keep:0 edit:5 reap:0 )

Original title: 'ssh not wroking'

Replies are listed 'Best First'.
Re: ssh not working
by lukeyboy1 (Beadle) on Jul 04, 2006 at 14:09 UTC
    surely, you're assuming that the path to ls is with the relevant user. Try this one, though I haven't actually tested it, to be honest.... :)
    use Net::SSH::W32Perl; my $ssh = Net::SSH::W32Perl->new($host,debug=>1); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("/bin/bash /bin/ls -lrt");
Re: ssh not working
by shmem (Chancellor) on Jul 04, 2006 at 16:28 UTC
    Maybe the shell on the remote system is just upset on e.g. your terminal settings or lack of those. Doing such as tset -Q or eval `resize` or the like, or asking Term? and getting no answer. I'd check that with an account that just has /bin/sh as login shell and all startup files disabled.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      i couldn't understand can u explain in detail
        First, can you login into the remote machine using an ssh command line client, such as http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html ?

        If you login to a remote machine, your login shell is spawned - one of sh, ksh, bash, csh, tcsh. You can lookup ypur shell in the file /etc/passwd on the remote machine. Please consult the login manual page of the remote system for details on the login process, and the manual page for your login shell for it's startup sequence.

        On startup, the login shell processes various rc files to set $PATH, the value of $TERM, the height and width of the terminal, system wide aliases for commands and so on.

        If such code as setting up the terminal is carried out regardless whether there was a controlling terminal (pty) set up for this session, various commands to set up the environment could hang. E.g. a shell could ask for your terminal type at the command prompt, if it is unable to determine it from the environment.

        Depending on the shell and remote system, the shell startup files are one ore more of /etc/profile, /etc/bashrc, /etc/csh.csh, $HOME/.profile, $HOME/.bashrc, $HOME/.cshrc etc. Check if those files contain terminal initialization code, and if possible, disable it.

        Since Net::SSH::W32Perl doesn't support the shell method, there should be no pty allocated, but you can explicitly disable it.

        Try the following:

        use Net::SSH::W32Perl; my $ssh = Net::SSH::W32Perl->new($host, debug => 1, use_pty => 0, ); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("ls");

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: ssh not working
by lukeyboy1 (Beadle) on Jul 04, 2006 at 14:10 UTC
    One other note: I'm assuming that you're connecting to a UNIX machine from a Windows Machine, with this one....Otherwise, the example I've given will NOT work! :)

      yes i am connecting from windows to Aix server and Sunsolaris
      copy of files from windows to Aix and SunSolaris servers
      can i use NET::SCP also in NET::SSH::w32Perl?

        Hi. You'd need to use them separately, as advertised on CPAN. However, the overhead, programming wise, is completely minimal. You probably, though, want to avoid having a username/password wired directly into a perl script, I would have thought......!