1751791 Members
5076 Online
108781 Solutions
New Discussion юеВ

Re: Script Help

 
SOLVED
Go to solution
Thad Jones
Occasional Advisor

Script Help

Hello All

I am trying to write a script that would be used to populate a file of the same size (approx 300K) onto a 1TB filesystem and then repeat the process until the filesystem is 100% filled.

I am not sure how to write the code for this at all.


Being that I am a newbie to this forum and linux in general as much help as you can provide here would be very much appreciated.


Thank you all and Happy Easter.

18 REPLIES 18
Ivan Ferreira
Honored Contributor

Re: Script Help

First, consider the number of inodes. if you run out of inodes you cannot write more files. You specify the number of inodes for a file system in the mkfs command.

Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Ivan Ferreira
Honored Contributor

Re: Script Help

You can use a script like this:

COUNT=0
while true
do
dd if=/dev/zero of=file$COUNT bs=300k
COUNT=`expr $COUNT + 1`
done
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Thad Jones
Occasional Advisor

Re: Script Help

Thank you for the reply.

I tried this script on my system and it builds one large file which is ok but what i am trying to do is build the same file size (300k or another size) and multiply it across the entire filesystem making millions of little files on a 1TB filesystem.

What should i do to the script you supplied in order to tweak it to the correct output i desire.

Thanks again.
Stuart Browne
Honored Contributor

Re: Script Help

Umm, nothing. That script will work as it is.

But the issue does reside in the fact that you'll probably run out of inodes before you run out of space using 300k files. If so, use larger files.
One long-haired git at your service...
Rasheed Tamton
Honored Contributor

Re: Script Help

Hello

What is the real objective here. Are you looking to wipe out the disk.

Regards.
Ivan Ferreira
Honored Contributor
Solution

Re: Script Help

You are right, one thing is missing in the script, try this:


COUNT=0
while true
do
dd if=/dev/zero of=file$COUNT bs=300k count=1
COUNT=`expr $COUNT + 1`
done
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Thad Jones
Occasional Advisor

Re: Script Help

Thanks again for the post Ivan. That worked fine.


Now just to add more to my confusion, i was told that they wanted to change this up a little bit so here goes what i need to do:

1) The application's output directory structure creates 100 directories called 00 thru 99.

2) since the filesystem size is 1TB and were using an output file size of 300K, if my math is correct that would equate out to about 3 million files for the whole filesystem.

3) based on #1 & #2, what i have to do now is take the script you provided me and let it write 30,000 files per directory while walking each directory and doing the same thing until it reaches the 99 directory.

Hope this is a simple thing for you cause it sure has me confused.


Thanks again
Sreedharamurthy K
Respected Contributor

Re: Script Help

IT is simple. Put the while script above in a for loop which creates 100 directories. Run that script at the top directory.

Something like this...

LIMIT=100

for ((a=1; a <= LIMIT ; a++))
do
mkdir dir$a
cd "dir$a"

cd ..
done
Thad Jones
Occasional Advisor

Re: Script Help

I will try that but one question here.

What can i do to limit the number of files created to 30,000 total per directory thus giving me 3 million files total?


Thanks for the help, it is much appreciated.