Newbie Question on Deleting Logs Script

Discussion in 'Perl Misc' started by Clifford Bracht, Dec 29, 2003.

  1. I was asked to create a Perl script that is able to when it runs
    delete Performance logs that are 30 days old from the current date on
    a Windows Platform. I didn't know Pearl prior to this and this is
    only after about 5 days of trying to teach myself. Here is my code. I
    was just wondering if anyone could lend some helpful suggestions that
    could maybe clear things up or get me going on the right path if I'm
    not already there. Thanks

    use Date::Calc qw:)all);

    eval
    {
    ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = System_Clock();
    };

    #$days = Date_to_Days($year,$month,$day);
    #($year,$month,$day) = Add_Delta_Days(1,1,1, $days - 1);
    $day_diff = Delta_Days($year1, $month1, $day1, $year2, $month2,
    $day2);
    $checkdate ($year1, $month1, $day1) = (@logdate); #Date Associated
    with the first or oldest perflog file
    $currentdate ($year2,$month2, $day2) = (Today([$gmt]); #Current Date
    $counterlog = ("C:\PerfLogs\system\");
    $tracelog = ("C:\PerfLogs\system\"); #Directory of the log files
    $alertlog = ("C:\PerfLogs\system\");


    @logarray("$counterlog","$tracelog","$alertlog",); #Array of the
    three performance logs
    @logdate("$logdate1","$logdate2","$logdate3",)


    if (($year,$month,$day) = Decode_Date_US($counterlog);
    {
    $counterlog = $logdate1;
    }
    else if
    {
    (($year,$month,$day) = Decode_Date_US($tracelog);
    $tracelog = $logdate2;
    }
    else if
    {
    (($year,$month,$day) = Decode_Date_US($tracelog);
    $alertlog = $logdate3;

    }
    else
    {
    exit;
    };
    #Reads in each Performance counter and checks the difference in days
    against 30 days

    for ($logcounter = 0; logcounter <= $#logarray; logcounter++)
    {
    while ($day_diff >= 30)
    {
    delete $checkdate;
    }
    else
    print "All files are current; No log files where deleted \n";
    }

    exit;
     
    Clifford Bracht, Dec 29, 2003
    #1
    1. Advertising

  2. Clifford Bracht

    Anno Siegel Guest

    Clifford Bracht <> wrote in comp.lang.perl.misc:
    > I was asked to create a Perl script that is able to when it runs
    > delete Performance logs that are 30 days old from the current date on
    > a Windows Platform. I didn't know Pearl prior to this and this is
    > only after about 5 days of trying to teach myself. Here is my code. I
    > was just wondering if anyone could lend some helpful suggestions that
    > could maybe clear things up or get me going on the right path if I'm
    > not already there. Thanks


    Your code (now snipped) is beyond repair.

    You are much too concerned about the date calculations. Perl has
    a file test operator "-M" that returns the age of a file (time since
    last modification, "perldoc -f -X" for details) in days directly.
    So, to decide if a file whose name is in $file should be deleted,
    just do

    delete $file if -M $file >= 30;

    To find the candidates in the first place, use the File::Find module.
    See "perldoc File::Find" for more.

    Anno
     
    Anno Siegel, Dec 30, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zlatko Hristov

    Python script to grep squid logs

    Zlatko Hristov, Apr 14, 2004, in forum: Python
    Replies:
    1
    Views:
    881
    Lee Harr
    Apr 15, 2004
  2. Harry Barker
    Replies:
    2
    Views:
    521
    Alf P. Steinbach
    Apr 19, 2006
  3. jack trades
    Replies:
    7
    Views:
    426
    jack trades
    Feb 8, 2008
  4. mmoalem
    Replies:
    1
    Views:
    241
    Mart.
    Sep 11, 2009
  5. crea
    Replies:
    2
    Views:
    417
    Nobody
    Dec 28, 2012
Loading...

Share This Page