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/*
)
-
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.– MadnessDec 8, 2011 at 9:41
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.
-
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.– MadnessDec 8, 2011 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. Dec 8, 2011 at 9:33
-
1Are you sure you want to have -print0 in there? Won't that confuse mailx? Dec 8, 2011 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.– MadnessDec 8, 2011 at 10:05
-
1
ctime
is inode change time. You may wantmtime
(modification time). Keep in mind users can override these timestamps; programs liketar
(when extracting) routinely do. If you want to be sure, you need to track checksums; consider Tripwire, Samhain, etc.– derobertDec 8, 2011 at 22:40