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

I'm trying to learn perl because I found some great scripts that I can use on the job, but I'm having trouble customizing the scripts, your help will be appreciated much. The Original code will take two line parameters and returns the information for one NT server service and it works fine for one server, but I want it to return information for several servers so I changed the code to read a file that has a list of servers and service I want information on. This is part of the original code that returns infromation for one server:
$DisplayName = shift @ARGV || die; $Machine = Win32::NodeName() unless( $Machine = shift @ARGV ); $Machine = "\\\\$Machine"; $Machine =~ s/^\\{2,}/\\\\/; if( Win32::Service::GetServices( $Machine, \%List ) )
This works fine for one server. I want it to read a file with a list of servers and I changed the code, but of course it doesn't work I get an error: Could not connect to \\650SAN: The RPC server is unavailable. I changed the code to the following from the code above. This reads the file okay, but I get the error: "Could not connect to \\650SAN: The RPC server is unavailable". for each line it reads from the file.
while ($Line = <>) { chomp($Line); $Line =~ s/^[ \t]+//; ### Check for spaces and tabs and remove $Line =~ s/[ \t]+$//; ### Check for trailing spaces and tabs and r +emove $Line =~ s/[ \t]+/ /g; ### Global Substitution to remove extra spac +es and ### tabs between words @ARGV = split(/ \\\\/, $Line); $DisplayName = shift @ARGV || die; $Machine = Win32::NodeName() unless( $Machine = shift @ARGV ); $Machine = "\\\\$Machine"; $Machine =~ s/^\\{2,}/\\\\/; if( Win32::Service::GetServices( $Machine, \%List ) )

Replies are listed 'Best First'.
Re: Read a config file
by Limbic~Region (Chancellor) on Apr 12, 2007 at 21:22 UTC
Re: Read a config file
by badaiaqrandista (Pilgrim) on Apr 12, 2007 at 23:38 UTC

    I never do Perl programming on Windows, but I think it's a network problem. It seems the script is having problem either in Win32::NodeName() or Win32::Service::GetServices(). I guess it's the latter. My wild guess would be that the latter is trying to query $Machine about what services it is running and this usually requires $Machine to run a service that sits on a specific port and can answer that query.

    As I said. I am not a Windows programmer and it's all just wild guess that I get from the error message.

    Hope that helps.

    -cheepy-
Re: Read a config file
by nega (Scribe) on Apr 13, 2007 at 17:52 UTC
    Your problem is probably in your split, and then cascading from there.
    @ARGV = split(/ \\\\/, $Line);
    The key you're trying to split on (' \\') probably doesn't exist on your line. That will cause the entire line to be put into $ARGV[0]. Then you shift the only item in @ARGV out into $DisplayName.
    $DisplayName = shift @ARGV || die;
    Then you attempt a second shift
    $Machine = Win32::NodeName() unless( $Machine = shift @ARGV );
    This of course will fail since you've already wiped out @ARGV. This causes Win32::NodeName() to return the hostname of the current machine. Finally you attempt to build a UNC path.
    $Machine = "\\\\$Machine"; $Machine =~ s/^\\{2,}/\\\\/;
    Win32::Service::GetServices() requires a hostname, not a UNC path. So what you end up feeding Win32::Service::GetServices() is a host name with two backslashes it. This causes it to fail, and windows generates the "The RPC server is unavailable" error.