Need help finding a program
Hello all,
What i'm looking for is a program or script that is able to monitor a folder and email a user whenever a file is written to it or updated in it. I have been looking around google but can't seem to find anything. Also if it could do this in any folder weather its a folder on a windows file server or a folder on a linux file server. |
Have a look at gamin.
|
This looks like it will work however would it be possible to program a script so it would only email the user if the folder hasn't been updated in 15min or so ? and if so how would you program such a script as my scripting is rusty.
*Edit* Actually i'm unsure if this will work. Here is what i'm trying to accomplish: The folder I have to check is on a windows file server. What happens is we have a temperature monitoring program that dumps data every 2 min or so into a folder. However sometimes it stops and when this stops its a problem. So i would like it to email a user if the folder hasn't been updated in 15 min or so. Not sure how I would accomplish this. I have both AIX, and Linux systems in the network if that helps any for finding a program to accomplish this. |
gamin is a library. There are python binding, so if I were to do it, I'd probably write a python program. I'll write if for you if you pay me lots of money :D
|
Actually scratch that, there's a command-line tool, dnotify, which looks like it would be more helpful.
|
Will dnotify continue to run after each update? or does it have to be put into a cron to schedule itself to continue to run?
|
Quote:
If you only want too check every few minutes, polling shouldn't be a problem. Some questions to find out if it'll be an easy task:
Assuming all these things are OK, it should be a pretty trivial matter to write a program to do this. As long the answer to point number 2 is yes, and you're not wanting to check inside sub-directories, you only need to look at the difference between the timestamp on the directory and the system time. I'd use perl just cos I'm most familiar with it: Code:
#!/usr/bin/perl -w Now there's two things to note about this sort of approach:
|
Cool thanks, i'll give this a whirl see how it works.
|
Thanks for all the help matthewg42 my scripting is very VERY rusty and it would of taken me days to fumble through to get something along those lines. However while testing this or putting it in place i was wondering how to alter the code so it only checks once or twice a day and checks the time stamps to see if they match the current date. If they don't match the current date send an email then.
This would reduce the network traffic as there is some give on how long the information can be outdated before serious problems occur. |
You can use modify the values of the $poll_sleep_time and $notify_age. The values are in seconds.
I woulnd't worry too much about the network traffic. Polling once every few minutes is not going to add any significant load. the stat call is very light. The only reason I can think of that you'd want to reduce the traffic is if you're on some connection which only connects when there is traffic, and you want the connection down most of the time. |
This may be a stupid question but would I have to schedule the cron to run the script over and over ? or would it only have to run it once a day ?
|
Not with this script - run it once, and it should keep running. Of course if it gets killed for any reason you'll have to re-start it.
You could modify the script to not do the repeating (while loop), and then call that modified script from cron according to some schedule you want. This may be a better approach since cron is probably more robust than expecting this script to keep running. Cron will be brought up automatically after some reboot, whereas you'd have to put this script in the init system somehow if you want it to start automatically after reboots. |
Hey thanks again. To take out the while i'd just take out the
While { and } i'd leave the sleep $poll in right? or should that go with the loop as well. |
Take out the "while(1) {" and the closing } in that block. You might as well remove the sleep commands too, and the definitions of the variables for the sleep timings as well. So it becomes like this (comments removed for brevity):
Code:
#!/usr/bin/perl -w Code:
5 * * * * /path/to/script |
Thanks for you input. My perl syntax is really bad I will have to crack open the manual and get a strong understanding of it once again, however the overall theory is mostly the same as i coded in vb, java, and C++ before, and cron setups are pretty simple. Thanks again for all your help you saved me a ton of time and troubleshooting.
|
All times are GMT -5. The time now is 09:43 PM. |