Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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.

Sreedharamurthy K
Respected Contributor

Re: Script Help

to limit, change the condition in while loop:

instead of while true change it to

while [ $COUNT â le 30000 ]
Sreedharamurthy K
Respected Contributor

Re: Script Help

You can refer to this guide. Has good examples and scripting info:

http://www.tldp.org/LDP/abs/abs-guide.pdf
Thad Jones
Occasional Advisor

Re: Script Help

The last line you wrote there came across with a bunch of special characters.

How would the while statement be coded as?


Thanks.
Court Campbell
Honored Contributor

Re: Script Help

the â should be a dash.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Court Campbell
Honored Contributor

Re: Script Help

wow, copying and pasting the crazy 'a' changed it to another character.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Sreedharamurthy K
Respected Contributor

Re: Script Help

Oh!! I didn't realize that copy paste would have changed it..

Thanks.. :)

Yes, it is -le
Court Campbell
Honored Contributor

Re: Script Help

Thad,

I think you should assign some points to Sreedharamurthy K. He has only done your work for you.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Court Campbell
Honored Contributor

Re: Script Help

Oh,

And Ivan as well.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Thad Jones
Occasional Advisor

Re: Script Help

Thank you all, this worked to perfection.

Kudos to all of you and yes points are forthcoming as well

BZ to all.


This forum rocks.