Hi
I'm trying to set up a CRON job, using PHP. I might do it a bit complicated:
My crontab line looks like this:
00,15,30,45 /home/marc/scripts/ftp.sh
I call a shell script to get rid of any output from the PHP script, hence
the >/dev/null.
My PHP script should read a directory to which people ftp files and mail a
list of people if the directory has changed (either files have been added or
removed, but nor if files have been changed). I keep a reference of the
directory listing from readdir() in a file called: ftp_ref.txt
Somehow I get some date-stamps into my reference file:
15-09-2000
18-09-00
That sort of stuff I can not explain and it seems to upset my script. Or do
I go wrong elsewhere?
Anybody see my mistake?
Cheers
Marc
Shell Script in /home/marc/scripts/ftp.sh:
home/marc/scripts/ftp.php >/dev/null
PHP Script in home/marc/scripts/ftp.php:
#!/home/marc/mybin/php
<?php
echo "started ...\n";
/ this script scans the directory $dir2check for any changes
as a reference, a file $dir_ref is kept.
If there are any changes, e-mails are sent to the addresses
in $mail_to.
/
//set variables
$dir2check = "/home/ftp_bin";
$dir_ref = "/home/marc/ftp_ref.txt";
$mail_to = "marc.burgauer@stortext.com";
// Script body
// read directory into $org_string
$org_string = "";
$handle=opendir($dir2check);
while (false!=($file = readdir($handle))) {
if (($file != ".") && ($file != "..")) {
$org_string .= $file."\n";
}
}
closedir($handle);
// load the reference string $ref
$ref_string = implode("\n",file($dir_ref));
if($ref_string != $org_string)
{
// update reference file
$file_pointer = fopen($dir_ref, "w");
fwrite($file_pointer, $org_string);
fclose($file_pointer);
// send mails
$org_string = "Result of reading directory
listing:\n\n".$org_string."\n\n<EOM>\n";
echo "mail result: " . mail($mail_to,"FTP directory
change",$org_string);
}
?>