Sign up to create your own snipts, or login.

Public snipts » elaforc's snipts The latest snipts from elaforc.

showing 1-2 of 2 snipts
  • Purge Directory
    use strict;
    
    # This file is used to remove old log files from the given directories.
    # The syntax of the file is
    # 		perl purgeMigrationDirectory.pl DirectoryName NumberOfDaysToPurge
    #
    # This will remove all old log files that are older than ARGV[1] days old
    # Old log files include any text file with _error.txt _log.txt _export.xml _audit.txt
    # It will not remove any other folders or files
    
    if(($#ARGV + 1) == 2){
    	&startThePurge($ARGV[0], $ARGV[1]);	
    }
    
    else{
    	&printHelp();
    }
    
    #print help message to the console if the correct number of arguments are not supplied
    sub printHelp{
    	print "You must provide the full path of the directory you wish to " .
    		  "purge of old migration log files and the number of days back you wish to purge.\nExample:\n\n" .
    		  "perl purgeMigrationDirectory.pl 'C:\\ICC Migration Tool\\InformaticaOutputDir' 60 would purge the directory of any of the log files that are older than 60 days.\n\n" .
    		  "See the script for more details.";
    }
    
    #purge migration log files
    sub startThePurge{
    	
    	#check to see if the directory exists
    	if (-d @_[0]){
    		my $inputDir = shift;
    		my $numFilesRemoved = 0;
    		my $numDays = shift;
    		
    		print "Removing old migration files from " . $inputDir . " that are older than " . localtime(time() - 60*60*24*$numDays) ."\n";
    		
    		#open input directory
    		opendir(DIR, $inputDir);
    		
    		#only look at files with the following appends
    		#_error.txt
    		#_log.txt
    		#_audit.txt
    		#_export.xml
    		#_query.txt
    		#_cntl.txt
    		foreach my $file (grep { /_(error.txt|log.txt|audit.txt|query.txt|cntl.txt|export.xml)$/} readdir DIR) {
    			my $tempdm = (stat $inputDir . "\\" . $file)[9];
    			my $age = int(-M $inputDir . "\\" . $file);
    			if($age >= $numDays){ #remove files older than two months
    				print "Removing file " . $file . " because it was last modified on " . localtime($tempdm) . " days old.\n";
    				unlink($inputDir . "\\" . $file); #remove file
    				$numFilesRemoved = $numFilesRemoved + 1;
    			}
    		}
    		
    		print "Removed " . $numFilesRemoved . " files from " . $inputDir . "\n";
    	}
    	
    	#directory does not exist
    	else{
    		print STDERR @_[0] . " does not exist.  Please try again";
    	}
    }
    

    copy | embed

    0 comments - tagged in  posted by elaforc on Sep 28, 2009 at 9:59 a.m. EDT
  • List Todays Modified Files
    find . -mtime -1 -type f -exec ls -lt {} \;
    

    copy | embed

    1 comment - tagged in  posted by elaforc on Sep 28, 2009 at 9:57 a.m. EDT
Sign up to create your own snipts, or login.