Pause shell script till folder doesn't change size anymore

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pause shell script till folder doesn't change size anymore
# 1  
Old 07-03-2011
Pause shell script till folder doesn't change size anymore


I recently would like to write a shell script that

1. Runs in the background (can be done with "&", but i'd be happy for other solutions to keep programs running)
2. Does its stuff
3 THEN checks a specified folder for a size change over time (say, each 5 seconds. AND ONLY continues with the next line in the script when said folders sizes doesn't change anymore.

I hope you got any good suggestions for me.

Thanks in advance
# 2  
Old 07-03-2011
Try this:


get_size(){ du -s "$1" 2>/dev/null | awk '$0=$1';}

while [ : ]; do
	# Script does its stuff
	sleep 5
	while [ "$(get_size "$DIR")" -ne "$dir_size" ]; do
		dir_size=$(get_size "$DIR")
		sleep 5
	echo "Size has not changed since the last 5 seconds. Loop to the top"

exit 0

Save this as '' or something, and run it with ./ &

Last edited by tukuyomi; 07-03-2011 at 05:39 PM..
This User Gave Thanks to tukuyomi For This Post:
# 3  
Old 07-03-2011
If I add something between the exit 0 and done, will that be executed after yhe size check has finished ?
Also, I'd prefer to have "the stuff that has to be done by the script" to be only executed once, and before that loop even starts, then loop till the sizechange isn't happenig anymore and after that continue with whatever I might still want.

Could this possibly be done in more compact form (one-liner lol ?)

Thanks for your answer.
# 4  
Old 07-04-2011


get_size(){ du -s "$1" 2>/dev/null | awk '$0=$1';sleep 5;}

# Script does its stuff

dir_size=$(get_size "$DIR")
while [ "$(get_size "$DIR")" -ne "$dir_size" ]; do
	echo 'Size has changed. Sleeping for 5 more seconds'
	dir_size=$(get_size "$DIR")

echo 'Size has not changed since the last 5 seconds.'

#Do other stuff

exit 0

This User Gave Thanks to tukuyomi For This Post:
# 5  
Old 07-04-2011
And the "script does it's stuf will ONLY be executed once, right Smilie ?
# 6  
Old 07-04-2011
Yes, # Script does its stuff and # Do other stuff will be executed only once.
# 7  
Old 07-04-2011
Perfect Smilie Thanks !

Will try that out ASAP !

---------- Post updated at 04:21 PM ---------- Previous update was at 02:44 PM ----------

And the path is changed by simply lets say, replacing this:

for example ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. UNIX for Dummies Questions & Answers

Shell Script for displaying the line till the target word

" Script for display sentences with special character" Hi, Could any one share a command how to display a line until my target word. For ex: My file has the content as: select * from db_wrk where col1 < col2 insert into table_name values('1','2','tst','wrk','dev','prod') My target... (10 Replies)
Discussion started by: Kalaiselvi66
10 Replies

3. Shell Programming and Scripting

UNIX script to get folder size

can any one help me with a unix command to find out the size of each directory for files placed between 2 dates i.e., date1 & date 2? (3 Replies)
Discussion started by: Codesearcher
3 Replies

4. Red Hat

Removing LVM Volume Group that doesn't exist anymore

Our SAN administrator decided to unpresent then destroy LUN's we were actively using as a volume group (all PV's in said volume group). Now every time I do a pvscan or whatever it complains about I/O errors trying to access those PV's. How do I get it to forget the VG existed completely? vgreduce... (7 Replies)
Discussion started by: thmnetwork
7 Replies

5. Shell Programming and Scripting

Log folder size monitoring script

Hi All, Can anyone refer to me a readymade script for the purpose of log folder size monitoring script. Example : I have a log folder of size 10 G, and as the logs keep accumulating the folder gets full and i have to manually zip/remove the files in order to keep the server running. Something... (1 Reply)
Discussion started by: findjai
1 Replies

6. Shell Programming and Scripting

How to introduce delay in Shell Script till a key stroke.

Hi All, How to introduce delay in the Bash/Shell Script till key stroke. Below is the requirement.. 1.Execute set of commands. 2.Display the message echo "press any key to continue" Introduce a delay till key stroke. 3.Execute next set of commands. Thanks in Advance Sunil.K (5 Replies)
Discussion started by: sunilrk07
5 Replies

7. Shell Programming and Scripting

How to pause a shell script

Hi, I've written a shell script to take photos with my camera. After every picture taken, the picture is transmitted to the computer via usb and then deleted on the camera. But sometimes there's an error and the picture is not deleted and so, after a certain time, the camera chip will be... (4 Replies)
Discussion started by: McLennon
4 Replies

8. UNIX for Dummies Questions & Answers

Sendmail not working anymore after resolv.conf change

Hi there, I am having a small issue with the mail function on our controllers. Recently we set up all the boxes as NFS slave servers and mail sending was not affected. We then had to change the servers addresses in resolv.conf and now email is being queued and not being sent. I have restarted... (3 Replies)
Discussion started by: lodey
3 Replies

9. UNIX for Dummies Questions & Answers

connection doesn't work anymore

Hello, first of all, I want to make myself clear about my language. I'm brazilian, so I ask you all to understand if i commit any mistake with the grammar. Here is the problem. Some days ago I needed to use a "sh" command in the Terminal (I use a Mac OSX 10.5.6) followed by a file... (0 Replies)
Discussion started by: anubisbr
0 Replies

10. AIX

how to change the font size of shell in $ prompt

Can any help me to change the default font type and its size.. To clear more about my question.. Once i login to my unix domain... the font it displaying is of small size... all my shell commands i am executing in $ prompt also carries the same style(ls, date and echo...) i searched whole... (2 Replies)
Discussion started by: tsjpraveen
2 Replies
Login or Register to Ask a Question