Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Need a notifying system for unmodified files
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
Naughtyus
Guru
Guru


Joined: 14 Jul 2002
Posts: 463
Location: Vancouver, BC

PostPosted: Tue Aug 19, 2008 5:25 pm    Post subject: Need a notifying system for unmodified files Reply with quote

Hi all,
I've just set up Gentoo with DRBD and samba to be the main file share for my company, and am quite pleased with the results. My next server problem has to do with archiving of data. I'd like to set up an automatic archiving system, or at least a notification system, but I'm not sure how to go about doing it.

Essentially I'd like something that will send me an email when files at a certain level (ie. /mnt/samba/A, /mnt/samba/B, ...) are left unmodified for somewhere around three weeks. Does anyone know of any good ways of doing this?
Back to top
View user's profile Send private message
massimo
Veteran
Veteran


Joined: 22 Jun 2003
Posts: 1141
Location: Austria

PostPosted: Tue Aug 19, 2008 7:22 pm    Post subject: Reply with quote

Using find with the appropriate arguments gives you a list of files you might be looking for. You could write the result to a file and send it as an attachment to yourself. Create a cronjob and your done.
_________________
Hello 911? How are you?
Back to top
View user's profile Send private message
Naughtyus
Guru
Guru


Joined: 14 Jul 2002
Posts: 463
Location: Vancouver, BC

PostPosted: Tue Aug 19, 2008 10:35 pm    Post subject: Reply with quote

Perfect! Don't know how I missed that obvious idea.

Is there a more efficient way of doing this than running a 'find * > all.txt', and taking the diff of that and 'find /mnt/dirs -mtime +21 > output.txt'?

Essentially I want to end up with a text file with a list of all the main directories where no files contained within have been modified within the last 21 days.
Back to top
View user's profile Send private message
a.b.
Apprentice
Apprentice


Joined: 23 Mar 2008
Posts: 218
Location: Anus Mundi, Germany

PostPosted: Tue Aug 19, 2008 10:51 pm    Post subject: Reply with quote

Does
Code:
find /mnt/dirs -mtime -21 -type d

do what you want?
Back to top
View user's profile Send private message
Naughtyus
Guru
Guru


Joined: 14 Jul 2002
Posts: 463
Location: Vancouver, BC

PostPosted: Tue Aug 19, 2008 11:48 pm    Post subject: Reply with quote

Unfortunately not - I think the -d switch only looks at the directory itself.

What I have is a file share like so:
/mnt/data/project1/..
/mnt/data/project2/..
/mnt/data/projectx/..
/mnt/data/project999/..

Essentially what I want is to have a list of the 'projectx' directories if and only if one or more files contained within it have not been modified in the last 21 days. The idea here is that if a file has been modified/created in the last 21 days, then a project is active, and there is someone who will be looking at it on a regular basis, so the normal backup schedule will catch this. If however there has been no activity in a project for 21 days, then it is possible that a project could be deleted without anyone noticing - after ~30 days, the backup media will be overwritten, and the project will disappear. To ensure that this doesn't happen, I want to 'archive' any/all of these inactive project directories - but I need some method of figuring out which projects are actually inactive (since I can't trust my users to tell me)
Back to top
View user's profile Send private message
a.b.
Apprentice
Apprentice


Joined: 23 Mar 2008
Posts: 218
Location: Anus Mundi, Germany

PostPosted: Wed Aug 20, 2008 12:21 am    Post subject: Reply with quote

Naughtyus wrote:
Unfortunately not - I think the -d switch only looks at the directory itself.

Yes, that's what it does. I assumed that a directory's mtime is updated whenever something inside it is changed, but unfortunately this seems to be the case only if files are added or removed. However, without the switch it should print all files which haven't been changed in the last 21 days.
Back to top
View user's profile Send private message
a.b.
Apprentice
Apprentice


Joined: 23 Mar 2008
Posts: 218
Location: Anus Mundi, Germany

PostPosted: Wed Aug 20, 2008 12:56 am    Post subject: Reply with quote

I think I've found a solution now. I doubt there is no more elegant solution but it should work if I've correctly understood what you want. You need a tiny script for that: (I've called it check.sh)
Code:
#!/bin/sh

if test $(find $1 -mtime -21 | wc -l) -eq 0; then
        echo $1
fi

It takes a directory as parameter and if it contains no files younger that 21 days prints it's name.

WIth
Code:
find /mnt/dir/ -type d -exec ./check.sh {} \;

You can get the list you wanted.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum