Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a reliable way to have a system that mails me the list of files that were modified in the past 24 hours inside a set of directories? (like /home/*/public_html/* and /home/*/*domains/*)

share|improve this question
    
Right now I'm using /usr/bin/find /home/*/public_html/ -ctime 0 -type f ( -name *.php -fprint php_files , -name *.js -fprint javascript_files ), I will have to modify it to include the subdomains and addon domains directory, and structure them with timestamps so I can check them more easily. –  Madness Dec 8 '11 at 9:41
add comment

1 Answer

If you want to find the files that are modified within the past 24hours, then this is the way.

find /usr/bin/find /home/*/public_html/ -ctime 0 -type f -print0 | mailx -s "Summary of the modified files in past 24hours" my_mail_address

If you want to find the same, from with in the past 24hrs-48hours then

find /usr/bin/find /home/*/public_html/ -ctime 1 -type f -print0 | mailx -s "Summary of the modified files in last 2 days" my_email_address

ctime 0 0 means within the last 24 hours, 1 means during the past 24 and 48 hours ago, 2 means between 48 and 72 hours ago, etc.

You can setup a a daily cronjob, that could run perhaps at the end of the working hours or at the start of the day. Or both of them, to know what files got changed during the working day and one when you are not around.

share|improve this answer
    
Will the * work for any subdir of /home? -- I need it to work with /home/foo/public_html/ but not /home/foo/bar/public_html/ also I somehow have to make it run on /home/foo/addon_domains/* and /home/foo/subdomains/* --- Also the cron manager of my system is able to send me a mail automatically with the output, so that simplifies the piping. –  Madness Dec 8 '11 at 9:13
    
Yes, it would not work for /home/foo/bar/public_html; since * globs the immediate results or files from the relative working directory of the shell. You could perhaps add another command line for add_domains and subdomains. Alternatively, for a better approach, I would do a list of the directories I need to search and execute the find command in loop for each of the directory in the list. Try it, let me know if you need a prototype. –  Nikhil Mulley Dec 8 '11 at 9:33
1  
Are you sure you want to have -print0 in there? Won't that confuse mailx? –  Folkert van Heusden Dec 8 '11 at 9:43
    
I'm giving up on the mail idea, mostly because dumping them to a file might give me a history of sorts, and I could use the data to graph up whatever I need visualizing, eventually. That opens up the option to run multiple commands, compound the files and eventually sort them. –  Madness Dec 8 '11 at 10:05
1  
ctime is inode change time. You may want mtime (modification time). Keep in mind users can override these timestamps; programs like tar (when extracting) routinely do. If you want to be sure, you need to track checksums; consider Tripwire, Samhain, etc. –  derobert Dec 8 '11 at 22:40
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.