LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 08: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 08:03 AM.
 
Old 03-19-2011, 09:42 AM   #2
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,087

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
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, 09:53 AM   #3
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,254

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

Original Poster
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, 11:45 AM   #5
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,087

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
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, 11:48 AM   #6
dinakumar12
Member
 
Registered: Mar 2010
Location: INDIA (chennai)
Distribution: centos
Posts: 271
Blog Entries: 7

Original Poster
Rep: Reputation: 18
thanks tredegar for your suggestion.
 
  


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

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

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