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

I have a script that runs on Linux, but does not run on Windows Perl. Its job is to ssh into a system, do a command, and return the results (In this example an 'ls' to a linux box). It uses Net::SSH::Perl for connection.

When I run this under Red-Hat Linux with Perl v 5.8.0, it runs as expected, returning the listing of the directory. However, under Windows (ActiveState Perl v5.8.8b817) an error is returned. The error is "The getwuid function is unimplemented at c:/Perl/site/lib/Net/SSH/Perl.pm line 110. Net::SSH::Perl was not in the default libraries, so I ran CPAN and installed it from there.

When this error arose, I removed the directories from the site/lib directory, and ran PPM (after installing the http://theoryx5.uwinnipeg.ca/ppms/ repository). I have the same error.

Has anyone else had problems using this module on Windows, and know what to do to fix it? I did a search using "Net::SSH::Perl Windows" and only saw a 'permission denied' entry.

Here is my example

use strict; use warnings; use Net::SSH::Perl; my $server = "mycomp.mywork.office"; my $ssh = Net::SSH::Perl->new($server, options => ["BatchMode yes"]) or die "Failed trying to create primary SSH connection\n"; $ssh->config->set('interactive', 1) unless defined $ssh->config->get('interactive'); $ssh->login("myname", "mypass") or die "Login failed (ssh)\n"; my $cmd = "ls -ltr"; my @response = $ssh->cmd("$cmd"); print "RESPONSE = @response\n"; output:: C:\perlfiles>perl sshtest.pl The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/Per +l.pm line 110.

Thanks!

Replies are listed 'Best First'.
Re: un-inplemented function in Net::SSH::Perl for Activestate Perl?
by BrowserUk (Patriarch) on Apr 10, 2006 at 15:38 UTC

    Both uses of getpwuid in NET::SSH::Perl can be trivially replaced by looking for the equivalent information from the environment

    • $ENV{USERNAME} for the first use (in _current_user());
    • $ENV{HOMEDRIVE} . $ENV{HOMEPATH} for the second (in _init() );

    However, if you are uncomfortable with using information extracted from the environment for these purposes, then you can obtain the information from the system, by:

    use win32:

    • Win32::LoginName()
    • Win32::GetFolderPath( Win32::CSIDL_PERSONAL )

    Obviously this would need to be done conditionally upon the value of $^O


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Hello My name is Joe from Toronto just read your solution to the he getpwuid function is unimplemented at :/Perl/site/lib/Net/SSH/Perl.pm line 110. problem When I step through my program the error appears when the perl.pm hits this line in the perl.pm file my $home = $ENV{HOME} || (getpwuid($>))7; Obviousley I don't understand how to update the code to solve this. Can you please help me where I need to update the code.. I tried to modify HOME with HOMPATH I don't know where to apply your suggestions $ENV{USERNAME} for the first use (in _current_user()); $ENV{HOMEDRIVE} . $ENV{HOMEPATH} for the second (in _init() ); Thank you so much for your time.

        Sorry Joe. As I have no way to test any changes made to Net::SSH::Perl, I can only suggest specific workarounds to individual problems. If you do not have the knowledge to apply and test those changes, any advice I give you would be a little of the blind leading the blind.

        The best I can suggest is that you contact the module's author(s) and see if he/they have interest in making and maintaining the appropriate changes.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: un-inplemented function in Net::SSH::Perl for Activestate Perl?
by wulvrine (Friar) on Apr 11, 2006 at 11:14 UTC
    First off, Thank you BrowserUK and Syphilis for trying to help me!

    BrowserUK:
    I tried your suggestions of modifying the source for net/ssh/perl.pm (using the environment method). It no longer complains about the function. However, it then stopped when trying to set the socket non-blocking. After doing some research, I found that you can not do that on windows. I commented out this line as well. Now the program actually runs, but does not run successfully. What happens now is that it connects up and sends the username and password pair. It never returns from when it sends the commands, just sits there and hangs forever (or at least the hour I waited for the ls command) I am not sure what to try after this but I have the same problem using Syp's suggestion.

    Syphilis:
    I tried your suggestion as well. Stepping through the program, it connects to the server, sends the username and password to log in, then sends the command down the socket. This has the same issue as Net::SSH::Perl after Browsers mods. It never returns from sending down the command. I do not know if the linux box can handle ssh2 but it is Red-Hat 2.4.26-1.ll.rh90.ccrmasmp SMP. Man SSH has the -s subsystem command for ssh2 but no other mention of it. Unfortunately I can not update this machine.

    Any other suggestions? I really appreciate the help.

      However, it then stopped when trying to set the socket non-blocking. After doing some research, I found that you can not do that on windows.

      Actually, you can. See the replies to Non-blocking socket read on Windows, in particular salva's reply and the links.

      However, it doesn't sound as if that is really your problem, though it might time out the failure to communicate if the port was set non-blocking.

      I know naff all about SSH. I've only ever used it through a terminal emulator and it "just worked".


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re: un-inplemented function in Net::SSH::Perl for Activestate Perl?
by syphilis (Archbishop) on Apr 11, 2006 at 01:13 UTC
Re: un-inplemented function in Net::SSH::Perl for Activestate Perl?
by wulvrine (Friar) on Apr 11, 2006 at 12:00 UTC
    I just read that non-blocking post, very interesting. I modified the Net/SSH/Perl.pm to set the socket non-blocking. But you are right, it doesn't alter the problem. (I didn't suspect it would as I am past the point of creation when the problem arises)
    Thanks for the suggestion though!