LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 12:01 PM   #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, 12:07 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
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, 12:23 PM   #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 12:26 PM.
 
Old 03-03-2010, 12:58 PM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
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, 01:41 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
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, 01: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 11:04 AM
Executing a command in Shell Script gjagadish Programming 7 10-15-2007 05:23 AM
command with shell script sunlinux Programming 2 12-29-2006 12:36 AM
Command in shell script Grassie Coetzee Linux - Software 1 03-13-2005 12:42 PM
Shell script login command? chup Linux - General 3 08-24-2003 07:43 PM


All times are GMT -5. The time now is 03:54 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration