Closed Thread Icon

Topic awaiting preservation: need help monitoring folder Pages that link to <a href="https://ozoneasylum.com/backlink?for=27563" title="Pages that link to Topic awaiting preservation: need help monitoring folder" rel="nofollow" >Topic awaiting preservation: need help monitoring folder\

 
Author Thread
CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 02-27-2006 21:18

I need to be able to monitor a folder which clients are going to be uploading files. I have it that they can't delete files once uploaded but I need to have the folders monitored to shoot an email when something is uploaded. Such as username and file name and date of upload.

I have read somethings about FAM which seems that would do the trick but the PHP I am working with does not have it compiled in there.

Any suggestions as to what to use? I would love it if it was PHP.

I'm kinda at a loss as to where to start to monitor the directories.

Thanks in advance for any and all help!!!

Later,

C:\

JKMabry
Maniac (V) Inmate

From: raht cheah
Insane since: Aug 2000

posted posted 02-27-2006 22:52

I assume you're using straight FTP instead of an uploading script? I assume this because the uploading could be made to report after upload.

Assuming LAMP as well as well?

If that's the case I'd recommend you take a script that inventories the directory then compares the current inventory list to the previous and use sendmail to notify you if there's anything new. Then you'd run said script via cron every hour (or whatever interval suits you).

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 02-28-2006 00:11

yeah just straight FTP and I don't think LAMP is installed either.

quote:

JKMabry said:

If that's the case I'd recommend you take a script that inventories the directory then compares the current inventory list to the previous .



Would this script just write the inventory to a file and then compair it? Or is there a better way?

Thanks!

Later,

C:\

JKMabry
Maniac (V) Inmate

From: raht cheah
Insane since: Aug 2000

posted posted 02-28-2006 02:17

LAMP = Linux/Apache/MySQL/PHP

it could write the incentory to file or database I spose, whichever you'd prefer

I assumed LAMP when saying cron but there should be some facility to execute scheduled tasks on just about any system.

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 02-28-2006 05:07

Actually all you'd need it to do is, perhaps, store one value: the date and time of when it last executed. From that it can check the date and time the file was put onto the server, and determine which files are 'new' from that. It will save a lot of time in the long-run if the contents of the directory start to encompass a lot of file.


Justice 4 Pat Richard

JKMabry
Maniac (V) Inmate

From: raht cheah
Insane since: Aug 2000

posted posted 02-28-2006 05:14

bested! *much* better

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 02-28-2006 20:10
quote:

Skaarjj said:

Actually all you'd need it to do is, perhaps, store one value: the date and time of when it last executed. From that it can check the date and time the file was put onto the server, and determine which files are 'new' from that. It will save a lot of time in the long-run if the contents of the directory start to encompass a lot of file.Justice 4 Pat Richard




I'm sorry but I am not really clear on what you are talking about.

When you say "When it was last executed". When what was last executed? The script?

So would I have a script that will read the contents of a directory and store that info in a text file? Then once that data is read store the date and time somewhere? See...I think I am getting myself really confused

If you wouldn't mind to elaborate a little on your idea I would greatly appreciate it!

Later,

C:\

JKMabry
Maniac (V) Inmate

From: raht cheah
Insane since: Aug 2000

posted posted 02-28-2006 22:54
quote:

CPrompt said:
When you say "When it was last executed". When what was last executed? The script?



Yes. Executed, run, fired etc

quote:

CPrompt said:
So would I have a script that will read the contents of a directory and store that info in a text file? Then once that data is read store the date and time somewhere?



files uploaded get a time stamp from the server. you would just need to check time stamps of the files, and compare them to the time that the script last ran and see if there's any new files

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 02-28-2006 23:57

ah...ok I gotcha.

quote:

JKMabry said:

Yes. Executed, run, fired etc



I knew what he ment by "executed", I just didn't know *what* was being executed. I think my cold might still be lingering around

Anyway, I think I can handle that. Then just set the cron job to shoot off the email. Or I could just build that into the script maybe. Anyway, I appreciate the help.

Later,

C:\

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 03-01-2006 17:54

CPrompt: What Operating System is this running on?

If it's a flavor of UNIX (such as Linux) you could create a script like

code:
find directory -newer time-stamp-file -print >> list-of-new-files
touch time-stamp-file



Run that on a cron and it will give you a list of all the new files since the cron was last run.

.



-- not necessarily stoned... just beautiful.

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-01-2006 19:18

yeah, it's RedHat. I take it that is a bash script? Not real familiar with it

Is that an actual script? or just some directions

<edit>

OK, I played around with that and it almost does the trick for me. I am not sure this is right but it makes a file called "list-of-new-files" and writes to it the directory and the file names.

I am guessing I can add a timestamp onto that (I think I can find the bash command for that).

However, the only thing is, is that it appends to the file instead of listing only the new stuff. If this is right, then I will get an email listing not only the new stuff but everything in that directory. Is that right?

I have gotten a php script working but am using filectime to return the timestamp. I know that is not really the creation time but I have the directory so that the files can not be overwritten or deleted so that should work fine. However, I am having some problems with it wanting to loop through the directory and display the filectime.

Just in case here is the php script I have done today:

code:
$directory = 'files'; //directory se are working with
$resc = opendir($directory); //open the directory

if (!$resc) {  //error handling
   echo "Problem opening directory $directory. Error: $php_errormsg";
   exit;
}

$files = array(); //put the files in an array

while ($filename = readdir($resc)) {  //loop through directory and grab all file names
   if (is_file($directory . '/' . $filename)) {
       $files[] = $filename;    // Add to the array
   }
}

$cnt = count($files); //see how many files are in the directory


for ($i = 0; $i < $cnt; $i++) {
	echo "<b>" . $files[$i] . "</b> <br />";     // Display filename or do whatever  
}



I tried to just add this after the echo but that didn't work

code:
echo date("F d Y h:i:s.", filectime($filename));



if I give the $filename a direct path to the file, it works but when I try to use it on the array, it crashes.

</edit>


Later,

C:\



(Edited by CPrompt on 03-01-2006 19:53)

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-01-2006 20:35

OK, I actually got the PHP script to work as far as displaying the file name and the "filectime".
Now I just need to figure out how to compair the timestamps of the files with the last time the cron job runs to shoot the email off.

Thanks for the help thus far!

Later,

C:\

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 03-02-2006 05:27

If you want to get a list of new files every time the cron runs change the >> to >. That will cause the command to truncate the file before it writes the new list.

When you say you want to time-stamp the file, do you mean change its mod time or do you mean create a filename with the time of creation in the name?

The commands I gave can be run from any shell including a bash shell script. One saftey mechanism you should use when creating the script is to specify the entire path to the command. For example on my system I would write:

code:
#! /bin/bash
/usr/bin/find ....
/bin/touch ...



The touch command sets the mod time of a file to the present time, in effect time-stamping it. That's what the second line of the code I showed does.

To create a new list file each time with a different filename for each list file, use the following:

code:
#! /bin/bash

time=`/bin/date "+%y%m%d%H%M%S"`
filename="$time-file.lst"
/usr/bin/find directory -newer time-stamp-file -print > $filename
/bin/touch time-stamp-file



.



-- not necessarily stoned... just beautiful.

« BackwardsOnwards »

Show Forum Drop Down Menu