I need a "file aging" utility [Archive] - Glock Talk

PDA

View Full Version : I need a "file aging" utility


gwalchmai
08-01-2005, 08:42
I have a directory on my network that we use for transfers between users. It's intended to be a very temporary file drop, but we have some folks who leave files on there forever, eventually filling it up.

I need a utility that will take a snapshot of the directory every day and compare it to the previous day's snapshot, then remove any files or subdirectories which have been there longer than, say, a month. Of course, we can't use the datestamps on the files because they will show the date created, not the date put in the transfer directory.

Before I start writing this I thought I'd check to see if the GT TT KB knew of anything like it (Windows, please).

Thanks!

prism
08-01-2005, 08:53
no idea.

but, could you do something like take ownership of the files, or rename them (like adding a hyphen). this might generate a new timestamp.

srhoades
08-01-2005, 10:26
Although I suck at them, what you need is a script. You can then schedule it to run once a day after everyone leaves.

GTIMANiac
08-04-2005, 03:40
Install PERL if you already havent. I also use KixTart where the standards will allow me to. Then you can setup an AT Job for this PERL file and modify it to fit your needs.

This is NOT my PERL script, found it on the web.
Ok a paste hosed the heck out of the formatting so here is a link.
http://www.gossamer-threads.com/forum/General_C8/Perl_Programming_F14/delete_files_in_directory_based_on_last_modified_date_P262056/

HerrGlock
08-04-2005, 04:32
Originally posted by gwalchmai
(Windows, please).

Well, hell. That eliminates a lot of the ones I know.

Have you looked at the automagic cleaning that WIN has built into it? Disk cleanup or something like that. It has a setting that you can delete, compress, or other things files that have not been touched in XXX days.

DanH

gwalchmai
08-04-2005, 05:10
Originally posted by HerrGlock
Have you looked at the automagic cleaning that WIN has built into it? Disk cleanup or something like that. It has a setting that you can delete, compress, or other things files that have not been touched in XXX days. No, I haven't, but that's a good suggestion. I tend to not look at Windows built-in utilities most of the time... ;)

HerrGlock
08-04-2005, 08:20
Originally posted by gwalchmai
I tend to not look at Windows built-in utilities most of the time... ;)

With good reason. But even as sooner or later a blind hog finds an acorn, MS screws up and puts something that actually is useful and generally tends NOT to screw up your machine in with the OS.

Don't tell 'em, they'll put a castrated version out next time and try to charge you to upgrade to the full version.

DanH

GTIMANiac
08-04-2005, 11:20
We use ActivePerl
http://www.activestate.com/Products/ActivePerl/

and KixTart
http://www.kixtart.org/

With those 2 languages you can do most anything you would need as far as automation.

I really think an AT Job to the .pl I posted the link to would be your best bet.

Tennessee Slim
08-04-2005, 12:17
I did this in my last job using native tools on a *NIX share hosted by VisionFS (which Windblows sees as a Win32 directory). GNU has those same *NIX tools ported for Win32 that should work.

What I did was run a ‘find’ command to look for files last modified more than 7 days ago. Then redirect the output to a ‘for’ statement to delete them.

Knowing that some knucklehead eventually would let a file get deleted that was essential to the survival of western civilization, I didn’t delete the files initially but moved them to a directory called “DeathRow” that was inaccessible to the user (but I never let the clients know). A similar script running on DeathRow deleted any file left there more than a month, giving them a 30-day grace period to notice the file had disappeared from the network share.

You can get the GNU DOS tools (free) at http://unxutils.sourceforge.net or http://userpage.fu-berlin.de/~wbg/unixdos.html.

gwalchmai
08-04-2005, 12:44
GTI and Slim, those look good. I'll look them over later. We moved the office two weeks ago and these kinds of things are getting tiny timeslices in between the constant "where's my printer?!!" crises. ;f

Thanks a bunch!

GTIMANiac
08-04-2005, 19:55
Originally posted by gwalchmai
GTI and Slim, those look good. I'll look them over later. We moved the office two weeks ago and these kinds of things are getting tiny timeslices in between the constant "where's my printer?!!" crises. ;f

Thanks a bunch!

Heh I work at the Amex Data Center, I own 150 windows boxes,trust me I know all about putting out fires, plus I am on call this week. As a Team we have 1500.

Cygwin is full of tools, though I would never install it on a production box. Same goes for the Resource Kit as well.

ngray
08-09-2005, 11:10
Simplest way is to simply empty the folder on the first of every month, but retain a trailing month.

1) Clear out /pub/LastMonthsBackup
2) Move /pub/*.* to /pub/LastMonthsBackup
3) RD /pub/LastMonthsBackup/LastMonthsBackup

Just run this on the 1st of every month. All you need is a scheduled task, a batch file, and xcopy.

Tennessee Slim
08-09-2005, 11:37
Originally posted by ngray
Simplest way....
...is not the Geek Way. In the interest of job security, it is essential that no one else in the shop be able to follow your scripts (without investing an inordinate amount of time). ;N

If there are any questions, Dogpile (I don’t Google) ...Dogpile for “how to's” on “unmaintainable code”. Here (http://codecourse.sourceforge.net/materials/How-To-Write-Unmaintainable-Code.html)‘s one I find particularly effective.

David_G17
08-09-2005, 12:20
Originally posted by Tennessee Slim
...is not the Geek Way. In the interest of job security, it is essential that no one else in the shop be able to follow your scripts (without investing an inordinate amount of time). ;N

code obfuscation == job security

srhoades
08-09-2005, 12:22
Originally posted by Tennessee Slim
...is not the Geek Way. In the interest of job security, it is essential that no one else in the shop be able to follow your scripts (without investing an inordinate amount of time). ;N

If there are any questions, Dogpile (I don’t Google) ...Dogpile for “how to's” on “unmaintainable code”. Here (http://codecourse.sourceforge.net/materials/How-To-Write-Unmaintainable-Code.html)‘s one I find particularly effective.

:gasp: He's like Wally's apprentice!

gwalchmai
08-09-2005, 13:06
Originally posted by Tennessee Slim
...is not the Geek Way. In the interest of job security, it is essential that no one else in the shop be able to follow your scripts (without investing an inordinate amount of time). ;N

If there are any questions, Dogpile (I don’t Google) ...Dogpile for “how to's” on “unmaintainable code”. Here (http://codecourse.sourceforge.net/materials/How-To-Write-Unmaintainable-Code.html)‘s one I find particularly effective. YES! Very Good! I am reminded of my friend Richard, who, in the late '80s, wrote a 1000 line batch file for installing NetWare. Essentially it ran setup.exe, but oh, what a fun time it had while doing it. ;f

GTIMANiac
08-09-2005, 19:21
Originally posted by ngray
Simplest way is to simply empty the folder on the first of every month, but retain a trailing month.

1) Clear out /pub/LastMonthsBackup
2) Move /pub/*.* to /pub/LastMonthsBackup
3) RD /pub/LastMonthsBackup/LastMonthsBackup

Just run this on the 1st of every month. All you need is a scheduled task, a batch file, and xcopy.

You could move a file that is only a day old then. Also check out robocopy instead of XCopy for large directory transfers or replication. I replicate several gigs a night without fail and write it out to a log file.

Toyman
08-10-2005, 09:16
Originally posted by gwalchmai
... we can't use the datestamps on the files because they will show the date created, not the date put in the transfer directory.
...

Files have 3 dates, Created, Modified, and Accessed. When the file is copied to the shared folder, the created date will be when that took place, the modified date will be the date it was last modified and is the date normally displayed in Windows Explorer.

In Windows Explorer, if you choose View->Details then right click on the header (Name, Size, Type, Date...) you will be presented with a context menu of what items you want to display. By default, the Modified Date is displayed, but you could choose Created Date and manually sort and remove items.

If that doesn't work for you, let me know and I could write a program that would do it automatically.

gwalchmai
08-10-2005, 09:33
Yes, I can use the created date programmatically. I was wondering if there was a util available.

Tennessee Slim
08-11-2005, 11:55
The GNU 'find' command for Win32 has most of the functionality of its *NIX counterpart, meaning it will search for (among other things), when created, last time accessed or modified.

Egyas
08-11-2005, 13:32
Originally posted by HerrGlock
With good reason. But even as sooner or later a blind hog finds an acorn, MS screws up and puts something that actually is useful and generally tends NOT to screw up your machine in with the OS.

Don't tell 'em, they'll put a castrated version out next time and try to charge you to upgrade to the full version.

DanH

Like Notepad. Hands-down the best "app" Microsoft ever wrote/bought/stole, etc. LOL

gwalchmai
08-11-2005, 13:35
Originally posted by Egyas
Like Notepad. Hands-down the best "app" Microsoft ever wrote/bought/stole, etc. LOL Shhh! They'll fix it by going back to EDLIN like they originally intended.

Egyas
08-11-2005, 13:39
Originally posted by gwalchmai
YES! Very Good! I am reminded of my friend Richard, who, in the late '80s, wrote a 1000 line batch file for installing NetWare. Essentially it ran setup.exe, but oh, what a fun time it had while doing it. ;f

Round here, we'd call him a BOFH. Incase I've just lost anyone, all geeks should be required to follow the adventures of Simon Travalgia, the Bastard Operator From Hell. He is a ficticous computer operator from the UK. You can read his exploits here.... (http://www.theregister.co.uk/odds/bofh/)

http://www.theregister.co.uk/odds/bofh/

Egyas
08-11-2005, 13:43
Originally posted by gwalchmai
Shhh! They'll fix it by going back to EDLIN like they originally intended.

Dude, I LEARNED on edlin, and liked it! lol. I'm a dinosaur, what can I say. ;)

gwalchmai
08-11-2005, 13:45
You young guys had it made. I learned on a SPO. ;)

gwalchmai
08-11-2005, 13:50
Originally posted by Egyas
http://www.theregister.co.uk/odds/bofh/ That's < clickety > wonderful!