LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-25-2016, 10:37 AM   #1
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Rep: Reputation: Disabled
wait and continue if directory stays same size


hi all,

i want to make a bash script so it can monitor directory sizes ie if it stays the same size (for a certain time) i want it to run the script but if there still copying and the directory increases in size do not run the script

i have heard "inotifywait" can do this?

cheers,

rob
 
Old 04-25-2016, 10:47 AM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Hi!

inotify might work, also check out watch:
Code:
man watch

[...]

EXAMPLES
       To watch for mail, you might do

              watch -n 60 from

       To watch the contents of a directory change, you could use

              watch -d ls -l

[...]
 
Old 04-25-2016, 11:38 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Yes, in a nutshell inotifywait will monitor a directory for file events i.e create, open, write, close etc. Normally by default it will wait forever for an event to happen but you can set a timeout value so it should be possible to create a script to handle your task. Might have to work out a few conditional checks since writing large files could be problematic.

Last edited by michaelk; 04-25-2016 at 11:40 AM.
 
Old 04-25-2016, 03:40 PM   #4
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
whats better -

watch

inotifywait

inotifywatch
 
Old 04-25-2016, 04:21 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
My preference would be inotifywait but maybe others have a better idea.
 
Old 04-25-2016, 04:31 PM   #6
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
will this work, if i put it in an if statement -

inotifywait -mrq -e access,modify,close,open,create,delete -t 180 /to_be_archived/"$DIR"
 
Old 04-25-2016, 06:01 PM   #7
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
directory size as in the number of things in the directory or the total on-disk size of the things in the inventory ?

monitor can not be used with a timeout

but it will work without it, as you only care if something is happening not how much of it

Last edited by genss; 04-25-2016 at 06:08 PM.
 
Old 04-27-2016, 04:35 AM   #8
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
i did this but it doesnt work over NFS, i will have to use the du command with some variables in it

inotifywait -rq -e modify,create,delete -t 60 /vol/cha-work/to_be_archived/audio/auto_archive/
 
Old 04-27-2016, 04:51 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
That is correct ionotify does not work with remote filesystems.
 
Old 04-27-2016, 04:50 PM   #10
robertkwild
Member
 
Registered: Feb 2015
Posts: 382

Original Poster
Rep: Reputation: Disabled
just thinking, would find command do this?
 
Old 04-27-2016, 06:13 PM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Maybe the ls -lt command to capture the latest file. If the file name or size remains unchanged after a specified time then run your script.
 
  


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] Keys: Continue to wait, or press S to skip mounting of M for manual recovery moshebagelfresser Linux - Hardware 2 02-22-2016 04:34 PM
(Continue to wait; or Press S to skip mounting or M for manual recovery) nightmare... phil1234567 Linux - Server 2 07-17-2015 06:46 AM
Starting udev: Wait timeout. Will continue in the background.[FAILED] 1300 Linux - Enterprise 1 06-25-2012 02:39 PM
Starting udev: Wait timeout. Will continue in the background.[FAILED] 1300 Linux - Newbie 0 06-25-2012 12:23 PM
How to create a bash script to wait for wget to finish and then continue danlee Linux - General 14 05-30-2008 11:21 AM

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

All times are GMT -5. The time now is 02:59 AM.

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