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

Monks,

Thanks for reading this and providing guidance.

I am attempting to use a CentOS server with Net:SSH2 module to connect and run commands via vshell (vandyke software) installed on the windows (win7 home premium) computer.

The purpose of this windows machine is to provide a “hop server” to a windows environment to run “psexec.exe” on the local server, gather the output and return to the perl script for crunching. I was using active state perl on the same windows box until I could not get alarms to work correctly. Besides, the permissions integrated with windows is a pain to setup after install.. Anyway.

I can connect to vshell and run “whoami”, “ver” and “dir c:\” without issue. The problem is when I run “psexec.exe” I only get half of the conversation.

However Running “ssh x.x.x.x” and running the command from the linux box to the vshell the command executes perfectly.

Replies are listed 'Best First'.
Re: Perl with Net::SSH2, vshell and psexec
by salva (Canon) on Feb 10, 2014 at 08:47 UTC
    Using Net::SSH2 correctly is quite hard and may involve digging into Net::SSH2 and libssh2 source code in order to discover how things really work and why your theoretical correct program doesn't.

    If you are on a Linux/Unix machine, I advice you to use Net::OpenSSH instead.

      Using Net::SSH2 correctly is quite hard and may involve digging into Net::SSH2 and libssh2 source code in order to discover how things really work and why your theoretical correct program doesn't.

      I second this! I use the perl Expect module to control the shell ssh command.

      I do a lot of cisco ios network automation using perl, and have published an open source suite of modules to handle connectivity, logging, testing, etc. They are posted at menzascripting.com. The Mnet::Expect module has my code for controlling ssh sessions (with authentication, prompt detection, telnet fallback, etc). Feel free to view or use that code. There a lot of quirk-mitigation built into it.

        I have used net::telnet and ssh::expect with great results with network equipment (hp, cisco, brocade, enterasys). For all my network needs (sh arp, mac, route, config backups). Not any problems with equipment.

        This psexec with hidden forking is a new monster altogether.

      Thanks for the reply..

      I have used net::openssh on another variant of these scripts.. Again no such luck. Currently I have 15 variants using: Net::SSH::Expect, Net::SSH2, Net::SSH::Perl, Net::OpenSSH. Thinking one of these would work.

      I still get a "Caption" output like the one stated in the original post using Net::OpenSSH. It seems somehow when the process is forked the SSH client (perl) loses this channel/output.

        What do you get when you run the command through ssh without a tty?
        ssh $WINDOWS_HOST 'c:\psexec.exe /accepteula c:\psexec.exe /accepteula + \\localhost wmic OS get Caption'

        psexec may be expecting a GUI environment, event if it doesn't seem to use it.

        The issue may also be related to quoting. Windows SSH servers use different approaches to launch commands. Some run them through cmd.exe, others just call the function CreateProcess from the Win32 API, etc.

Re: Perl with Net::SSH2, vshell and psexec
by shmem (Chancellor) on Feb 10, 2014 at 07:14 UTC

    Running ssh on a terminal, both STDOUT and STDERR are going to your tty. According to Net::SSH2::Channel, the normal mode is to read STDERR separately. Try calling ext_data('merge') on your channel object.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
      Thanks for the tip, however I used the "$chan->ext_data('merge');" in the script without any different results.
Re: Perl with Net::SSH2, vshell and psexec
by t_rex_joe (Sexton) on Feb 11, 2014 at 13:18 UTC
    All,

    There is known bug in psexec.exe that has reoccurring with the streams (STD IN/OUT/ERR). I found another tool called "paexec" that works without issue.

    -- PAExec. replaces and fixes bugs for psexec by powertools - v1.22 - Source https://github.com/poweradminllc/PAExec - Binary http://www.poweradmin.com/paexec/
    Joe