Wait and continue if directory stays same size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wait and continue if directory stays same size
# 1  
Old 04-25-2016
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, but theres others aswell

watch
inotifywatch

cheers,

rob
# 2  
Old 04-25-2016
Quote:
Originally Posted by robertkwild
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
Please clarify what you mean by "size of a directory": A "directory" as such is a data structure in a filesystem and has no "size" that could change.

Do you mean the (sum of the sizes of the) file(s) in a certain directory? Like a directory being filled with files (say, by ftp or similar means) and you want to process the directory only when this process has stopped?

If so: there is the du command that should do what you want. You can specify the directory and use the "-s" option to make the calculation recurse through the underlying hierarchy. I suggest you first read the man page of du to see what it can do and then construct a small loop which checks if the reurned value changes or doesn't change. There is no need for something like watch or whatnot where a simple shell-loop is sufficient.

I hope this helps.

bakunin
# 3  
Old 04-25-2016
i want it to monitor for file size growth and if it doesnt grow any more within a certain time period, execute the rest of the script

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"
# 4  
Old 04-25-2016
Please don't ask the same question in two threads! It is almost impossible for people trying to help you to follow one discussion being held in two places!

As I said in post #40 in the thread titled Script to tar/rsync/rm multiple folder names:
Quote:
The size of a directory tells you very little about whether or not files in that directory are growing, and (if any files have ever been removed from a directory) even if a new file is created in a directory, its size might not change.

It would be much better if you would create a hidden directory under /to_be_archived (such as /to_be_archived/.in_progress/project), move everything into that directory, and then after that project directory contains everything you want to archive, issue the command:
Code:
mv /to_be_archived/.in_progress/project /to_be_archived/project

which will be an atomic operation. Your existing script won't see the hidden directory so it won't see .in_progress/project until it is ready to process after it has been moved up.
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 04-27-2016
i did this but it doesnt work over NFS, i will have to use the du command with some variables in it as bakunin said

Code:
inotifywait -rq -e modify,create,delete -t 60 /vol/cha-work/to_be_archived/audio/auto_archive

---------- Post updated at 04:50 PM ---------- Previous update was at 04:39 AM ----------

just thinking, would find command do this?
# 6  
Old 04-27-2016
No.

The proper way to do this, is asking whatever's creating the files. If you can't do that directly, maybe you can do so at a remove, with lsof, to see if any files in the folder in question are actually open by anything.
# 7  
Old 04-27-2016
what do you mean whatever has created the file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

If file pattern exists in directory then continue

he below looks in $dir for any pattern of fileone. As is, it executes but only returns File found if the exact format in the script exsists. Why isn't a pattern of fileone being looked for and if it is in $dir, File found. I think that is what should happen. Thank you :). dir=/path/to if... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

3. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies

4. Shell Programming and Scripting

while [[ $# -gt 0 ]] stays in the loop

Hi, I have(ksh): ... while ] do fullPath=$(grep -s '/' $1 | wc -l) echo $fullPath if ]; then fi echo "Wrong, full path" shift done ... I tried to do: (5 Replies)
Discussion started by: chish
5 Replies

5. Shell Programming and Scripting

Line in bash script to wait for x feedbacks and then continue

I have a script that runs a console/terminal command on the server and what is want is for each of the multiple success reports fed back from the clients (echo-ed out onto the conosle) to be counted and after x number of reports reboot the server. The Details: The command (program) is... (0 Replies)
Discussion started by: dp123
0 Replies

6. Shell Programming and Scripting

Shell script: If a file stays in a particular directory more than 30 min send an email

Hi , I am new to shell scripting. i have a requirement say i will receive a file in a directory say /xyz.if that file stays in that directory more than 30 min i need to get a mail to my outlook.this should run for every 20 min in crontab. can anyone help me? (8 Replies)
Discussion started by: muraliinfy04
8 Replies

7. UNIX for Dummies Questions & Answers

directory tree with directory size

find . -type d -print 2>/dev/null|awk '!/\.$/ {for (i=1;i<NF;i++){d=length($i);if ( d < 5 && i != 1 )d=5;printf("%"d"s","|")}print "---"$NF}' FS='/' Can someone explain how this works..?? How can i add directory size to be listed in the above command's output..?? (1 Reply)
Discussion started by: vikram3.r
1 Replies

8. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

9. UNIX for Dummies Questions & Answers

detect file size then quit or continue

Hi Guys, I'm running a cron that mails me a file every night. The file is based on form input from the web and each evening after I mail it I delete and start a new file by the same name. It's a csv file so I preload a line of headers into the file. So far, so good. On days when no one inputs... (5 Replies)
Discussion started by: steven99
5 Replies

10. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies
Login or Register to Ask a Question