LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-19-2011, 07:02 AM   #1
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271
Blog Entries: 7

Rep: Reputation: 18
how to break copy process when folder size reaches its maximum


Hi all,

I have written a script.

#/bin/bash
a=`du -sh /root/samplefolder | cut -f1`
echo $a > testfile
sed -i 's/M//g' testfile
b=`cut -f1 testfile`
if [ $b -ge 20 ]
then
echo size of samplefolder reaches 20M so cannot copy files to that folder
chattr +i /root/samplefolder
else
echo size for samplefolder is lessthan 20M
fi

The aim of this script is, when the folder reaches 20M then attributes will be set to that particular folder so that no newfiles and folders cannot be created or copied to that samplefolder.

i run the script every second with the help of LQ member suggestion.

whenever i copy a file morethan 20M to that folder its getting copied fully and then the attributes were applied.

But i dont want this to happen, when the folder reaches its maximum current write operation to that folder should be stopped automatically with a error.

How to do this.

Kindky post your suggestions.


Thanks in advance,
Dinesh.

Last edited by dinakumar12; 03-19-2011 at 07:03 AM.
 
Old 03-19-2011, 08:42 AM   #2
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
I think you are going about this the wrong way.

What you can do is create and mount a filesystem of size 20MB.
You can then copy files to it until it reaches 20MB and then the last operation will fail because "no space left on device".

This is more efficient than running a script every second.

As root:

Code:
# create a 20MB file
dd if=/dev/zero of=vfs bs=1M count=20
# make a filesystem, with no reserved space, in that file
mkfs.ext3 -m 0  vfs
# create a mountpoint
mkdir /mnt/max20M
# mount the file
mount -t ext3 -o loop vfs /mnt/max20M
# let anyone access it
chmod 777 /mnt/max20M
Now you have your "folder" at /mnt/max20M that cannot hold more than 20MB of files. Actually the number will be a little less than 20MB because the filesystem itself takes up some of that space. I'll let you work out how to adjust the dd command if you want exactly 20MB of storage space.
 
1 members found this post helpful.
Old 03-19-2011, 08:53 AM   #3
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Or use some quota tool, it was created for that purpose.
 
Old 03-19-2011, 10:28 AM   #4
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271

Original Poster
Blog Entries: 7

Rep: Reputation: 18
hi tredegar,

If i need to extend the size can i do that with out un mounting. If possible kindly post me the code.
 
Old 03-19-2011, 10:45 AM   #5
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Quote:
If i need to extend the size can i do that with out un mounting.
No, you can't.
 
1 members found this post helpful.
Old 03-19-2011, 10:48 AM   #6
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271

Original Poster
Blog Entries: 7

Rep: Reputation: 18
thanks tredegar for your suggestion.
 
  


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] what is the maximum heap size for a process anoopbt Programming 3 03-17-2011 11:12 PM
What is the maximum allocatable heap size for a process? jaewlee Ubuntu 7 04-02-2010 09:53 PM
setting maximum folder size msound Linux - General 5 03-26-2010 11:36 AM
Is it possible to set a maximum folder size? KDE bglnelissen General 1 03-20-2005 07:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:58 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