[EMAIL PROTECTED] wrote:
On aussie, i.e. the wiki server, I've got a script that emails me when uploaded files have been changed. It works well on many days, but every few days it misbehaves.

Here's the algorithm of the script:

* Check if the script has been executed within the last day, if not:
** Generate a list of files using a command similar to:
    cd /home/lyx/www/pmwiki
    find uploads -printf '%TY-%Tm-%Td %TH:%TM  %-8s  %p\n' > files
Is this the exact command? If not, what is it? Or better yet, can you send me the script?
** 'diff' this list with a previous list of files, and email me
   the difference if it is non-empty.

Normally 'files' will begin with something like:

    2007-01-21 18:15  4096      uploads
    2006-07-16 16:02  4096      uploads/SiteTest
    2005-04-28 17:59  4096      uploads/SiteTest/ADir
    2004-02-11 11:54  4         uploads/SiteTest/ADir/Aßß.txt
    2007-02-06 09:21  10        uploads/SiteTest/aFile.txt
    2005-05-24 12:50  4096      uploads/SiteTest/test
    2003-11-22 17:29  10        uploads/SiteTest/test/aFile.txt
    2005-04-28 18:01  4096      uploads/SiteTest/test/test4
    2003-11-22 17:56  10        uploads/SiteTest/test/test4/aFile.txt
    2005-03-31 21:35  11        uploads/SiteTest/test/test.txt
    ...

However, every few days it will _only_ contain the following line:

    2005-05-19 22:46  28        uploads

What's going on here?
* Why only a single line, where are the rest of the files?
* Why is the date 2005-05-19 ???
This could be caused here:
if($action == 'browse' || $action == '')
 if(FilesNotifyIsItTimeToUpdate())
   register_shutdown_function('FilesNotifyUpdate', $pagename, getcwd());
Note the `getcwd()' that provides the second argument. Then when you get here:
function FilesNotifyUpdate($pagename, $dir='') {
 global $FilesNotify;
 $curdir = getcwd();
 if($dir) { flush(); chdir($dir); }
You'll be chdir'ing to whatever getcwd() returned before, and that must depend upon what browse action is underway. So you're NOT chdir'ing to /home/lyx/www/pmwiki all the time. To see where you are going, check the date on /home/lyx/www/pmwiki/test/wiki/uploads/.

Here's a different idea: Why not just do this as a bash script and install it as a cron job? Then you don't have to access this script on every browsing action. Something along these lines (yes, it's ugly with all the error checking included):
 !#/bin/bash
 WORKDIR=wiki.d;
if ! cd /home/lyx/www/pmwiki/; then echo $0 failed to chdir...!; exit 1; fi if ! [ -d $WORKDIR ]; then if ! mkdir $WORKDIR; then echo $0 failed to mkdir...!; exit 1; fi
 if [ -e $WORKDIR/files ]; then
if ! cp $WORKDIR/files $WORKDIR/files.0; then echo $0 failed to cp...!; exit 1; fi;
 else
   if [ ! -e $WORKDIR/files.0 ]; then
if ! touch $WORKDIR/files.0; then echo $0 failed to touch...!; exit 1; fi
   fi
 fi
 find uploads -printf '%TY-%Tm-%Td %TH:%TM  %-8s  %p\n' > $WORKDIR/files
 diff $WORKDIR/files $WORKDIR/files.0
And of course cron will send you the output if it's your cron job.

Richard


I'm stumped, any ideas?

/Christian

PS. I might be able to "fix" the script by checking if 'files' contains a single line, and then try to repeat the 'find' command. Not a pretty solution though...

PPS.
The list of files are stored in:
    /home/lyx/www/pmwiki/wiki.d/files
in case anyone wants to look.

The actual script is in
    /home/lyx/www/pmwiki/farm.d/cookbook/filesNotify.php



--
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto

Reply via email to