Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: deletes timestamped logfiles (MMDDYY) based on actual time

by blakem (Monsignor)
on Feb 08, 2002 at 01:14 UTC ( #144004=note: print w/replies, xml ) Need Help??


in reply to deletes timestamped logfiles (MMDDYY) based on actual time

If I was going to write this, I would use Time::Piece and the code would look like:
#!/usr/bin/perl -wT use strict; use Time::Piece; my $daysago = 28; my $datadir = "/var/adm"; # MMDDYY of 28 days ago my $timestring = localtime(time-$daysago*24*60*60)->strftime("%m%d%y") +; my $file = "$datadir/backup.$timestring.log.Z"; -e $file or die "File '$file' doesn't exist"; unlink $file or die "Couldn't unlink '$file'";

-Blake

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://144004]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2021-03-08 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (124 votes). Check out past polls.

    Notices?