troubleshooting Question

Inputting the Filename for systems as a parameter for a perl script

Avatar of Simon336697
Simon336697Flag for Australia asked on
PerlScripting Languages
12 Comments2 Solutions244 ViewsLast Modified:
Hi guys hope you can help.

Id like to turn the following working script, into one that I can manually type in the name of the text file, which houses the computers.
eg. -c <computerlist.txt>

At the moment, it uses a text file of computer names, which I have hard coded the name, which is fine, but Id like to modify the script, so I if I can put any filename in as a parameter. It's also a way so that I dont have to hardcode the text file in the script.

Here is the code.


sub RunRegQuery {
my $regoutput = `reg query "\\\\$System\\HKLM\\Software\\Network Associates\\TVD\\VirusScan Enterprise\\CurrentVersion" /v szProductVer 2>&1`;
   if($regoutput =~ /Error: The system was unable to find the specified registry key or value/i){
      print U "$System: Key not found!\n";
   if($regoutput =~ /Error:/){
      print U "$System: Unknown error: $regoutput\n";
my $version;
   if( $regoutput =~ /REG_SZ\s+([\d.]+)/ ){
   else  {
      print U "$System: Unknown version: $regoutput\n";
   if($version =~ /^8\b/) {
      print "$System: At Version 8! Version is $version\n";
      print Y "$System: AT VERSION 8! (Version is $version)\n";
   print "$System: NOT AT VERSION 8! ! (Version is $version)\n";
   print N "$System: NOT AT VERSION 8! (Version is $version)\n";

open Y,">vs8.txt" or die "vs8.txt $!";
open N,">novs8.txt" or die "novs8.txt $!";
open U,">unknown.txt" or die "unknown.txt $!";
open (Store, "< systems.txt") or die "can't open systems: $!";
while( <Store> ) {
   $System = $_;
   chomp ($System);
   print "\nPolling $System..........\n";
   $result = system ("net use \\\\$System\\ipc\$ \"password\" /user:$System\username > NUL"); #piping to NUL - remove output.
   if ($result !=0) { #if not successful
      print "$System: Unreachable!\n";
      print U "$System: Unreachable!\n";
   else {
      print "$System: Connected!\n";
      system ("net use \\\\$System\\ipc\$ /delete /y > 2NUL > NUL"); # Delete previous connection
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros