LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-03-2010, 11:01 AM   #1
hawk__0
Member
 
Registered: Nov 2008
Posts: 105

Rep: Reputation: 15
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?
 
Old 03-03-2010, 11:07 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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?
 
Old 03-03-2010, 11:23 AM   #3
hawk__0
Member
 
Registered: Nov 2008
Posts: 105

Original Poster
Rep: Reputation: 15
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!

Last edited by hawk__0; 03-03-2010 at 11:26 AM.
 
Old 03-03-2010, 11:58 AM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
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
 
Old 03-03-2010, 12:41 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by hawk__0 View Post
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!
 
Old 03-03-2010, 12:42 PM   #6
hawk__0
Member
 
Registered: Nov 2008
Posts: 105

Original Poster
Rep: Reputation: 15
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Shell script to monitor or watch the disk space.... small help needed vikas027 Programming 5 10-21-2007 10:04 AM
Executing a command in Shell Script gjagadish Programming 7 10-15-2007 04:23 AM
command with shell script sunlinux Programming 2 12-28-2006 11:36 PM
Command in shell script Grassie Coetzee Linux - Software 1 03-13-2005 11:42 AM
Shell script login command? chup Linux - General 3 08-24-2003 06:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration