Hey all, I need some help, I have asked this question in other places but no one has answered it. Here I go. I have written a script that will directory walk through my Win32 file server and make sure a certain group is contained on every directory. I am traversing 5 Terabytes of data so there are many folders. The problem that I am having is that the longer I run my script the more ram it takes up. I an doing a directory walk, I am not sure if that is the problem. Thanks for the help.
# This scrip will travers a given depth of folders and see if an admin + (or user) # is not in that group. When you call the script, you have to give 3 +arguments # from the command line # 1. firs you must give a number of levels that you want to dig do +wn into # 2. You must give a starting point to that you want to search\tra +verse # 3. you give a path and file name of an output file that will be +written # to when a fooder does not have the group and correct rights # This will walk a directory when given 2 arguments, the depth and the + directory # For some reason when I run this script I get 2 lines or errors all t +he time so I # call a clear screen to clear the errors. It has somting to do when +I call the # Win32::Perms and File::DirWalk use File::DirWalk; use Win32::Perms; # Clear the screen system("cls"); # Setting up the sub rutiene sub getperms; sub ERROR; # Getting command line arguments my($arg1,$arg2,$arg3) = @ARGV; chomp($arg1,$arg2,$arg3); # changing the color to regular in the command prompt system("color 07"); # Making sure that all the arguments are filled if(length($arg1) < 1 or length($arg2) <1 or length($arg3) <1) { system("color A"); print "You need to give 3 arguments\n\nThe 1st is the folder depth + that you want to search.\n\n"; print "The 2nd is the path you want to traverse\n\n"; print "The 3rd is the path and file name for the log file such as +c:\\somting_err.txt\n\n"; print "EXAMPLE somthing.pl 3 t:\\A_Directory \"c:\\program files\\ +temp\\error log.txt\"\n\n"; print "REMEMBER to add quotes \" \" to any path if there are any s +paces in that path\n\n"; exit; } # Changing the output color system("color 4e"); print "Folder_Look_For_Admin_Recrus.exe v1.0\n"; my $x = 0; # Setting up and executing the directory walk my $dw = new File::DirWalk; my @all; $dw->onDirEnter(sub { my ($dir) = @_; getperms $dir; # if($x == 1000){ # print $dir . "\n"; # $x = 0; # } # $x++; return File::DirWalk::SUCCESS; }); # Running directory walk $dw->setDepth($arg1); $dw->walk("$arg2"); sub ERROR { my($error) = @_; chomp($error); open(WRITER, ">>". $arg3); print WRITER "lala " . $error . "\n"; close(WRITER); } # This is the perms sub sub getperms { # We need to have a collection varieble to add all the output into +. We will use this variable to parse information $strMaster = ""; my ($obj) = @_; $Perm = new Win32::Perms($obj); # print "Permissions for: $obj ,\n"; $strMaster = $obj; $read = 'READ_CONTROL SYNCHRONIZE FILE_READ_EA FILE_READ_ATTRI +BUTES'; $write = 'SYNCHRONIZE FILE_WRITE_EA FILE_WRITE_ATTRIBUTES'; $RW = 'READ_CONTROL SYNCHRONIZE FILE_READ_EA FILE_WRITE_EA +FILE_READ_ATTRIBUTES FILE_WRITE_ATTRIBUTES'; $RE = 'READ_CONTROL SYNCHRONIZE FILE_READ_EA FILE_EXECUTE F +ILE_READ_ATTRIBUTES'; $mod = 'DELETE READ_CONTROL SYNCHRONIZE FILE_READ_EA FILE_WRITE +_EA FILE_EXECUTE FILE_READ_ATTRIBUTES FILE_WRITE_ATTRIBUTES'; $full = 'STANDARD_RIGHTS_ALL FILE_READ_EA FILE_WRITE_EA FILE_E +XECUTE FILE_DELETE_CHILD FILE_READ_ATTRIBUTES FILE_WRITE_ATTRIBUTES'; $Perm->Dump(\@List); foreach $acct (@List) { my(@Permissions); next if ($acct->{Entry} ne "DACL"); Win32::Perms::DecodeMask($acct->{Mask},\@Permissions); my $final = join(" ",@Permissions); if($final =~ m/$full/) { # print ",$acct->{Account} , Full"; $strMaster = $strMaster . ",$acct->{Account} <> Full"; } elsif ($final =~ m/$read/) { # print ",$acct->{Account} , Read"; $strMaster = $strMaster . ",$acct->{Account} <> Read"; } elsif ($final =~ m/$write/) { # print ",$acct->{Account} , Write"; $strMaster = $strMaster . ",$acct->{Account} <> Write"; } elsif ($final =~ m/$RW/) { # print ",$acct->{Account} , Read Write"; $strMaster = $strMaster . ",$acct->{Account} <> Read Write"; } elsif ($final =~ m/$RE/) { # print ",$acct->{Account} , Read Execute"; $strMaster = $strMaster . ",$acct->{Account} <> Read Execute" } elsif ($final =~ m/$mod/) { # print ",$acct->{Account} , Modify"; $strMaster = $strMaster . ",$acct->{Account} <> Modify"; } else { # print ",$acct->{Account} , SPECIAL <--> $final"; $strMaster = $strMaster . ",$acct->{Account} <> SPECIAL <--> $ +final"; } } # Change this search to serch for the group that you are looking f +or if($strMaster !~ m/Administrators <> Full/){ # <---------------- +----- Change this group, this is the group that you want to search fo +r # Print error line to log file ERROR $strMaster; print $strMaster . "\n"; } } print ("\n\nThe End\n\n"); system("color e");

In reply to Memory Leaks can it be helped? by timgerr1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.