S
Simon
Hi guys.
Would appreciate very much your help on this one.
What I want to do is:
Create a perl script that:
a) Reads a computer list (done)
b) Connects to each one (done)
c) Uses reg.exe to query a registry value (done)
d) Pipe the computer with its BuildVersion number to the appropriate text
file according to Buildverson number retrieved (having problems). Im having
problems with the split function. Please see below..
================================================================= go.pl
sub RunRegQuery {
open (REGQUERY, "reg query \"\\\\$System\\HKLM\\Software\\test\" /v
BuildVersion|");
while (<REGQUERY>) {
@lines = <REGQUERY>;
foreach $line (@lines) {
chomp $line;
print "$line\n";
}
}
}
#================================================= Create files for logging.
open U,">unknown.txt" or die "unknown.txt $!";
open H,">6.11.txt" or die "6.11.txt $!";
open S,">6.7.txt" or die "6.7.txt $!";
open L,">6.5.txt" or die "6.5.txt $!";
open C,">6.2.txt" or die "6.2.txt $!";
#================================================= Read a Computer List.
open (Store, "< systems.txt") or die "can't open systems.txt: $!";
foreach $line (<Store>) {
chomp($line);
$System = $line;
$result = system ("net use \\\\$System\\ipc\$ \"password\"
/user:$System\\administrator");
if ($result !=0) { #if not successful
print U "$System: Unreachable\n";
}
else {
print "$System: Successful.\n";
sleep 3;
RunRegQuery();
system ("net use \\\\$System\\ipc\$ /delete /y >
2NUL > NUL"); # Delete previous connection
}
}
close (Store);
exit;
--------------------------------------------------------- EOF
=====================================================================
Output:
C:\@>go.pl
The command completed successfully.
predator: Successful.
! REG.EXE VERSION 3.0
HKEY_LOCAL_MACHINE\Software\test
BuildVersion REG_SZ 6.11
C:\@>
================================================================= Comments:
Ive deliberately left out the split function to make this easier to read, as
this is where
Im having problems.
What Im trying to do is grab the following line in the above output:
BuildVersion REG_SZ 6.11
and then, write
$System: 6.11
to the appropriate filehandle.
For example, if the value is 6.11, write "$System 6.11" to the 6.11.txt
file, then continue through the computer list.
I know I have to use a split function (I believe), but having big issues
with it.
In the above, I printed the $line, just so you guys could see what is
returned.
Would appreciate very much your help on this one.
What I want to do is:
Create a perl script that:
a) Reads a computer list (done)
b) Connects to each one (done)
c) Uses reg.exe to query a registry value (done)
d) Pipe the computer with its BuildVersion number to the appropriate text
file according to Buildverson number retrieved (having problems). Im having
problems with the split function. Please see below..
================================================================= go.pl
sub RunRegQuery {
open (REGQUERY, "reg query \"\\\\$System\\HKLM\\Software\\test\" /v
BuildVersion|");
while (<REGQUERY>) {
@lines = <REGQUERY>;
foreach $line (@lines) {
chomp $line;
print "$line\n";
}
}
}
#================================================= Create files for logging.
open U,">unknown.txt" or die "unknown.txt $!";
open H,">6.11.txt" or die "6.11.txt $!";
open S,">6.7.txt" or die "6.7.txt $!";
open L,">6.5.txt" or die "6.5.txt $!";
open C,">6.2.txt" or die "6.2.txt $!";
#================================================= Read a Computer List.
open (Store, "< systems.txt") or die "can't open systems.txt: $!";
foreach $line (<Store>) {
chomp($line);
$System = $line;
$result = system ("net use \\\\$System\\ipc\$ \"password\"
/user:$System\\administrator");
if ($result !=0) { #if not successful
print U "$System: Unreachable\n";
}
else {
print "$System: Successful.\n";
sleep 3;
RunRegQuery();
system ("net use \\\\$System\\ipc\$ /delete /y >
2NUL > NUL"); # Delete previous connection
}
}
close (Store);
exit;
--------------------------------------------------------- EOF
=====================================================================
Output:
C:\@>go.pl
The command completed successfully.
predator: Successful.
! REG.EXE VERSION 3.0
HKEY_LOCAL_MACHINE\Software\test
BuildVersion REG_SZ 6.11
C:\@>
================================================================= Comments:
Ive deliberately left out the split function to make this easier to read, as
this is where
Im having problems.
What Im trying to do is grab the following line in the above output:
BuildVersion REG_SZ 6.11
and then, write
$System: 6.11
to the appropriate filehandle.
For example, if the value is 6.11, write "$System 6.11" to the 6.11.txt
file, then continue through the computer list.
I know I have to use a split function (I believe), but having big issues
with it.
In the above, I printed the $line, just so you guys could see what is
returned.