#!/usr/bin/perl ###################### Globals ######################################### %keydirs; ## Hash for use in tracking directories @d; @ed; $profile = `\. ~/.profile`; # Load user profile $log_for_days = eval(86400 * 91); ## 91 is the number of days for retention ###################### Globals ######################################### &date_calc; &get_dirs; foreach $dir1_(@d) { chomp $dir1_; @dir_ = split(/\//,$dir1_); $num = eval(@dir_ - 1); $logfile = "@dir_[$num].$myLog"; $delfile = "@dir_[$num].$delTime"; if(-e "$dir1_/logs/$delfile") { $del_old_recs = `rm -f $dir1_/logs/$delfile`; } chop $dir1_; get_ldat($dir1_); open(ARCLOG,">$dir1_/logs/$logfile"); print ARCLOG "@data1"; close(ARCLOG); undef @data1; } ############################ Subroutines ############################### sub date_calc { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time - 86400); $syear = $year+1900; $smon = sprintf '%02d',$mon+1; $smday = sprintf '%02d',$mday; $shour = sprintf '%02d', $hour; $smin = sprintf '%02d', $min; $ssec = sprintf '%02d', $sec; $myTime = "$smon/$smday/$syear $shour:$smin:$ssec"; $myLog = "$syear"."$smon"."$smday"; ($fsec,$fmin,$fhour,$fmday,$fmon,$fyear,$fwday,$fyday,$fisdst) = localtime(time); $fsyear = $fyear+1900; $fsmon = sprintf '%02d',$fmon+1; $fsmday = sprintf '%02d',$fmday; $fshour = sprintf '%02d', $fhour; $fsmin = sprintf '%02d', $fmin; $fssec = sprintf '%02d', $fsec; $fmyTime = "$fsmon/$fsmday/$fsyear"; ($dsec,$dmin,$dhour,$dmday,$dmon,$dyear,$dwday,$dyday,$disdst) = localtime(time - $log_for_days); $delyear = $dyear+1900; $delmon = sprintf '%02d',$dmon+1; $delmday = sprintf '%02d',$dmday; $delhour = sprintf '%02d',$dhour; $delmin = sprintf '%02d',$dmin; $delsec = sprintf '%02d',$dsec; $delTime = "$delyear"."$delmon"."$delmday"; } sub get_dirs { open(DIRFILE,"; close(DIRFILE); foreach $directory(@directories) { next unless $directory !~ /\#/ig; chomp $directory; @dire = split(/(encrypt|decrypt|\:)/,$directory); if(! exists($keydirs{$dire[2]})) { $keydirs{$dire[2]} = 1; @d = (@d,$dire[2]); } } } sub get_ldat { $dirtoget = "@_"; chomp $dirtoget; if(-e "$dirtoget/encrypt") { @encdir = `ls -Af $dirtoget/encrypt 2>&1`; } else { @encdir = ""; } foreach $endir(@encdir) { chomp $endir; if($endir !~ /\./) { if(-e "$dirtoget/encrypt/$endir/sample.log") { @data = `cat $dirtoget/encrypt/$endir/sample.log`; $cnt=0; $dcnt= eval(@data - 1); foreach $row(@data) { if($row !~ /$fmyTime/i) { $cnt++; } else { last; } } $cnt = eval($cnt - 1); $icnt=0; for($icnt=0;$icnt<= $cnt;$icnt++) { push @data1,$data[$icnt]; } $cnt = eval($cnt + 1); for($icnt2=$cnt;$icnt2<=$dcnt;$icnt2++) { push @data2,$data[$icnt2]; } open(LOG,">$dirtoget/encrypt/$endir/sample.log"); print LOG "@data2"; close(LOG); } } undef $cnt; undef $dcnt; undef @data; undef $row; undef $icnt; undef $irow; undef $irow2; undef @data2; } if(-e "$dirtoget/decrypt/sample.log") { @data = `cat $dirtoget/decrypt/sample.log`; $cnt=0; $dcnt=@data; foreach $row(@data) { if($row !~ /$fmyTime/i) { $cnt++; } else { last; } } $icnt=0; for($icnt=0;$icnt< $cnt;$icnt++) { push @data1,$data[$icnt]; } for($icnt2=$cnt;$icnt2<=$dcnt;$icnt2++) { push @data2,$data[$icnt2]; } open(LOG,">$dirtoget/decrypt/sample.log"); print LOG "@data2"; close(LOG); } undef $cnt; undef $dcnt; undef @data; undef $row; undef $icnt; undef $irow; undef $irow2; undef @data2; }