The guy who developed the original script for checking for changed files had an example for modifying the exec command so that certain files or folders are excluded:
Code:
exec('find /home/username/public_html -name error_log -prune -o -path \'/home/username/public_html/components/com_sef\' -prune -o -cmin -62 -print', $last_changed);
This works very well - just make if setting up the cron tab through cpanel that you leave the email address blank or else you will be receiving emails every hour when the script runs.
Here is my entire script:
Code:
<?php
/*
This file e-mails you a list of all modified files in a certain directory
Run this file via cron every hour
"Find" shell command code syntax from:
http://www.mydigitallife.info/2006/01/19/find-files-that-are-modified-today-or-since-certain-time-ago-in-unix/
and from:
http://linux.about.com/od/commands/l/blcmdl1_find.htm
*/
// Shell command that finds all files below a certain directory that modified within the last 62 minutes
// Replace the file path (absolute or relative to this script's location) as necessary
exec('find /home/username/public_html/ -name error_log -prune -o -path \'/home/username/public_html/administrator/components/com_sef\' -prune -o -path \'/home/username/public_html/components/com_sef\' -prune -o -cmin -62 -print', $last_changed);
// Only e-mail the results if anything has changed
if ( count ( $last_changed ) > 0 ) {
// E-mail settings
$sendto = "E-mail receiver <myemail@mydomain.com>";
$sendfrom = "File change script <noreply@mydomain.com>";
$sendsubject = "yoursite.com file change notice";
// Results of files last modified
$email_output = 'Files modified in the last hour:';
$email_output .= "\n";
$email_output .= "\n";
$last_changed_files = implode ( "\n", $last_changed);
$email_output .= $last_changed_files;
// Mail the file
// You can also use the PEAR Mail package (http://pear.php.net/package/Mail) or a similar script for more robust mailing
// Line break, which we will used for the headers
$send_eol = "\r\n";
$send_headers = 'From: ' . $sendfrom . $send_eol;
$send_headers .= 'Reply-To: ' . $sendfrom . $send_eol;
$send_headers .= 'Return-Path: ' . $sendfrom . $send_eol;
// Send!
mail($sendto, $sendsubject, $email_output, $send_headers);
}
?>