LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Watch command in a shell script (https://www.linuxquestions.org/questions/programming-9/watch-command-in-a-shell-script-792909/)

hawk__0 03-03-2010 11:01 AM

Watch command in a shell script
 
I want to make a script that runs in cron that watches a folder for changes, and IF a change occurs, I'd like to make it email me. Is it possible to get output from the watch command when it's running in the background?

catkin 03-03-2010 11:07 AM

As long as the script itself receives all the output but it would be relatively complex coding (watch runs until killed so you would have to run it in a sub-process and kill it at intervals, all within a timed loop) and inefficient.

Have you considered inotify instead of watch?

hawk__0 03-03-2010 11:23 AM

I've never heard of inotify. I did an apt-cache search in debian lenny, and never found 'inotify', but I did find inoticoming. Sounds to be exactly waht I need - triggers actions when files hit an incoming directory. Thanks!

crts 03-03-2010 11:58 AM

You might also want to consider incrond. Here are some links to give you an idea of it.

http://linux.die.net/man/8/incrond
http://linux.die.net/man/5/incron.conf
http://linux.die.net/man/5/incrontab

catkin 03-03-2010 12:41 PM

Quote:

Originally Posted by hawk__0 (Post 3884144)
I've never heard of inotify. I did an apt-cache search in debian lenny, and never found 'inotify', but I did find inoticoming. Sounds to be exactly waht I need - triggers actions when files hit an incoming directory. Thanks!

Sorry -- inotify was introduced with kernel 2.6.13 and I think Lenny's is before that.

Glad the disinformation lead you to a solution, though! :)

hawk__0 03-03-2010 12:42 PM

Thanks for the suggestions. I like the idea of incrond the best but I find it slightly confusing. I have the daemon running, but how do I define a permanent file it will use? or how often the directory is checked? How would I make it watch for an incoming zip file?

For incoming zip file, I'm assuming I have to edit my incrond file (which I still don't know how to permanently define) to something along the lines of this:

/home/me/zips/ IN_CREATE *.zip

I think that's still wrong, however.


All times are GMT -5. The time now is 11:20 PM.