Absurd Minds

More than 100 years without a motto.
It is currently 21 Nov 2024 19:28

All times are UTC-04:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 13 Jun 2014 13:12 
Offline
User avatar

Joined: 25 Mar 2010 19:07
Posts: 8392
Because the workshop doesn't manage map collections very well, our custom map server has a lot of unused maps in it. These would be maps that maybe I added to the collection and then later removed.

I would like to create a script, executable through crontab, that deletes files, and hopefully their parent directories, if the file has not been accessed in a particular amount of time.

I'm thinking I would just scan for files by Access date, then delete files, then scan for empty directories, then delete them. Would this work?

_________________
Server list
Donate


Top
   
PostPosted: 13 Jun 2014 13:50 
Offline
User avatar

Joined: 25 Mar 2010 19:07
Posts: 8392
It looks like the relevant command would be
Code:
find ./directory -atime +N -exec rm {} \;
where N is the number of days ago that you would want it to have been accessed last. Eg, +10 would give you a list of all files that have been accessed 10 or more days ago. It would then execute a removal command for those files.

Now all I have to figure out is how to delete empty subdirectories.

_________________
Server list
Donate


Top
   
PostPosted: 13 Jun 2014 13:54 
Offline
User avatar

Joined: 25 Mar 2010 19:07
Posts: 8392
Alright, it looks like I can delete empty directories using this command:
Code:
find . -empty -type d -delete
Last step is figuring out how to get this together into a useful script.

_________________
Server list
Donate


Top
   
PostPosted: 13 Jun 2014 14:03 
Offline
User avatar

Joined: 25 Mar 2010 19:07
Posts: 8392
Current script delete.sh: Jero, can you fact check this before I execute it and fubar my maps?
Code:
#!/bin/bash

find ~/go/*/csgo/maps/workshop -atime +14 -exec rm {} \;
sleep 5
find ~/go/*/csgo/maps/workshop -empty -type d -delete

_________________
Server list
Donate


Top
   
PostPosted: 13 Jun 2014 18:06 
Offline
User avatar

Joined: 25 Feb 2012 19:18
Posts: 908
Location: Ontario, Canada
Looks okay, even though I haven't touched a Linux console in months. You could just move them to an "unused" directory instead of deleting them.

_________________
Image


Top
   
PostPosted: 13 Jun 2014 18:15 
Offline
User avatar

Joined: 25 Mar 2010 19:07
Posts: 8392
Well, they will just redownload if they're actually part of the compilation but not being used. (eg, if there is a map on the server but maybe it's less popular). Then I'd have tons of duplications.

_________________
Server list
Donate


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC-04:00


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Limited