Wilson, Josh --- Systems Analyst --- GO wrote:
All,

Hello,

I'm trying to determine what is wrong with this script. Here is what
I'm trying to do:
1.) Export the output of the following command to a file located at
c:\perl\bin\log\accessreport.log
Global "Domain Admins" ARFW > c:\perl\bin\accessreport.log
2.) For each line of information that is returned, execute the
following command (Ex. 1st line of output is jlw5038)
Cscript "c:\program files\resource kit\useraccount.vbs" /N
jlw5038 |grep FullName
3.) I want the information that is grepped to be thrown into a separate
file called accessreport2.log
For whatever reason, I never make it to my first print statement within
the foreach code shown below. This is a perl script created in a
Windows Environment for a windows environment and I'm running ActivePerl
5.8 on my system.
Any help is appreciated!

[code reformatted for readability]

BEGIN:
# Exporting Windows 2000 Resource Kit command output to file
system("global \"Domain Admins\" ARFW > c:\\perl\\bin\\log\\accessreport.log");
# Creating a foreach statement for each line of accessreport.log which
in this case is a userid.
open(IDS, "type c:\\perl\\bin\\log\\accessreport.log |");

As someone else pointed out you could just open the file directly in perl.

@IDLIST=<IDS>;
foreach $USERID (@IDLIST)
{
    if ($USERID != "")

You are using a numerical comparison operator on a string. If you had had warnings enabled then perl would have warned you of this mistake.

    {
        chomp($USERID);
        print("Processing UserID: $USERID\n");
        open(FULLNAME, "cscript \"C:\\program files\\resource kit\\useraccount.vbs\" 
/N $USERID |grep FullName |");
        chomp($NAME=<FULLNAME>);
        close(FULLNAME);
        open(REPORT, ">c:\\perl\\bin\\logs\\accessreport2.log");

You are overwriting the file for each $USERID

print REPORT ("$USERID - $NAME\n");
close(REPORT);
}
}
EOF:

This may work better:

open GLOBAL, 'global "Domain Admins" ARFW |'
    or die "Cannot open pipe from 'global' $!";
open REPORT1, '>', 'c:/perl/bin/logs/accessreport.log'
    or die "Cannot open 'c:/perl/bin/logs/accessreport.log' $!";
open REPORT2, '>', 'c:/perl/bin/logs/accessreport2.log'
    or die "Cannot open 'c:/perl/bin/logs/accessreport2.log' $!";

while ( my $USERID = <GLOBAL> ) {
        next unless $USERID =~ /\S/;
        print REPORT1 $USERID;

        chomp $USERID;
        print "Processing UserID: $USERID\n";

open FULLNAME, "cscript \"C:\\program files\\resource kit\\useraccount.vbs\" /N $USERID |"
or die "Cannot open pipe from 'cscript' $!";
while ( <FULLNAME> ) {
last if /FullName/;
}
chomp( my $NAME = $_ );
print REPORT2 "$USERID - $NAME\n";


        close FULLNAME or warn $! ? "Error closing 'cscript' pipe: $!"
                                  : "Exit status $? from 'cscript'";
        }

close GLOBAL or warn $! ? "Error closing 'global' pipe: $!"
                        : "Exit status $? from 'global'";
close REPORT1;
close REPORT2;




John -- use Perl; program fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to