Visit Our UNIX and Linux User Community


Script to fill the file system mount with empty files to desired size

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Script to fill the file system mount with empty files to desired size
# 1  
Old 11-14-2012
Script to fill the file system mount with empty files to desired size

We are regularly using for our testing, where we are manually filling up the mount with desired size with following command

Code:
dd if=/dev/zero of=file_2GB bs=2048000 count=2000

We are planning to automate the task where taking input for % [(say 70% of mount size)]of size as one input and the name of the file system mount as other input. Could you please help me on this.

Thanks,
Chandra
# 2  
Old 11-14-2012
Code:
threshold=80
FStoFill=/tmp
set -- $(df -k $FStoFill | tail -1)
dd if=/dev/zero of=$FStoFill/zerofile.$$ bs=1k count=$((($threshold*$2/100)-$3))

But the dd command above may be set up to be faster (search for the msg posted by Alister )

The idea was to use /dev/null instead, as well as seek to avoid a bunch of useless zero writting so something like :

Code:
dd if=/dev/null of=dummy seek=37580963840 bs=1

Just tweak it in a way you can replace the dd if=/dev/zero... of the first code with the more optimized dd if=/dev/null ... command

Last edited by ctsgnb; 11-14-2012 at 04:27 PM..
This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 11-14-2012
Hello,

I tried to run the below code and getting the following error. could you please help.

dd: bad arg -5211234
Usage: dd [if=InputFile] [of=OutputFile] [cbs=Number] [fskip=Number]
[skip=Number] [seek=Number] [count=Number] [bs=Number] [span=yes|no]
[ibs=Number] [obs=Number] [files=Number] [conv=Parameter[, ...]]


Here is the code that i am using.

Code:
#!/bin/ksh
threshold=20
FStoFill=/tmp
set -- $(df -k $FStoFill | tail -1)
dd if=/dev/zero of=$FStoFill/zerofile.$$ bs=1 count=$((($threshold*$2/100)-$3))

# 4  
Old 11-14-2012
What arguments are you running the script with?
# 5  
Old 11-14-2012
what output does
Code:
df -k yourfilesystem | tail -1

give ?

Maybe this will be more reliable :
Code:
threshold=70
FStoFill=/tmp
set -- $(df -k $FStoFill | tail -1 | awk '{$1=$1;print $(NF-4),$(NF-3)}')
dd if=/dev/zero of=$FStoFill/dummy bs=1K count=$((($threshold*$1/100)-$2-1064))

Keep some space of 1064K in case threshold is set at 100% (i dont know why this 1064 number but it worked fine so...).
You should add some test on the threshold : (should not be set higher than 100%, and should not be set lower than current use)

Last edited by ctsgnb; 11-14-2012 at 07:51 PM..
This User Gave Thanks to ctsgnb For This Post:
# 6  
Old 11-14-2012
Here is the output i am getting for the below command
Code:
 df -k /tmp | tail -1
/dev/hd3          5767168   5557264    4%      811     1% /tmp

Please let me know wt are the expected parameters. i was running with out parameters as the threshold and filesystem has been added in the script.

Thanks,
Chandra
# 7  
Old 11-14-2012
In :
Code:
count=$((($threshold*$1/100)-$2-1064))

$1 is supposed to refer to the total number of 1K block
$2 is supposed to refer to the number of block currently in use

So you should adapt the code to make the right calculation:
Code:
set -- $(df -k $FStoFill | tail -1 | awk '{$1=$1;print $(NF-5),$(NF-5)-$(NF-4)}')
dd if=/dev/zero of=$FStoFill/dummy bs=1K count=$((($threshold*$1/100)-$2-1064))

This User Gave Thanks to ctsgnb For This Post:

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

how to mount a file system from a solaris server into an hp-ux system

Hi all I wonder if its possible to mount on a hp-ux server a file system that was previously mounted on a solaris 10 server. The LUN is on NetApp stoarge. The problem on hp-ux I cannot do pvcreate on the lun (disk) because contains data. Any help will be appreciated FR (2 Replies)
Discussion started by: fretagi
2 Replies

2. Shell Programming and Scripting

Script which fill data in XML file

Hello, I need help for writing a script that fills already generated xml file with data from oracle database and random sequences. For example if we have the following tags: <ns1:message> <ns1:messageId> </ns1:messageId> <ns1:languageCode> </ns1:languageCode>... (10 Replies)
Discussion started by: zb99
10 Replies

3. Shell Programming and Scripting

Symbolic link to an empty file shows size 2

Hi, I have created an empty file and a symbolic link to a file. But when I issue the following commands, I am getting the output 2. stat -c "%s" linkfile du -hb linkfile Why this is happening? (4 Replies)
Discussion started by: royalibrahim
4 Replies

4. Shell Programming and Scripting

Script to check file system size

Dears, the output of this command df -h | tr -s ' ' | cut -f5 -d' ' is capacity 24% 0% 0% 0% 0% 1% 0% 24% 24% 0% 93% 1% (4 Replies)
Discussion started by: xxmasrawy
4 Replies

5. Shell Programming and Scripting

Compare columns and rows with template, and fill empty slots.

Hi, I'm working on a script that will take the contents of a file, that is in a row and column format, and compare it to a arrangment file. Such that if there is any or all blanks in my content file, the blank will be filled with a flag and will retain the row and column configuration. Ex. ... (2 Replies)
Discussion started by: hizzle
2 Replies

6. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

7. Shell Programming and Scripting

Unix file empty.. but size is greater than zero??/

Hi, I have a file by redirecting some contents in unix shell. Even when there is no content that is being redirected, the file size still shows greater than zero. but even if there is no matching pattern the file APPRES has size greater than 0bytes. awk -f AA.awk $logfile>APPRES... (3 Replies)
Discussion started by: justchill
3 Replies

8. UNIX for Dummies Questions & Answers

Trying to empty file using > but the file size increasing when next append

AIX 5.3 / KSH I have a Java application which creates a log file a.log. I have a KSH script which does the following action cp a.log /directory2/b.log > a.log After this the file size goes to 0 as per "ls -l" Then next time when the application writes into this file, the file size... (4 Replies)
Discussion started by: firdousamir
4 Replies

9. UNIX for Dummies Questions & Answers

how to mount a file system of a remote machine to local file system

Hi friends, In my case, there are serveral PCs running Linux in a LAN. I would like to to mount the directory /A_river of machine-A to the file system of another machine machine-B so that I can access files in that directory. I do not know how to do this. The situation is complicated by... (2 Replies)
Discussion started by: cy163
2 Replies

10. Shell Programming and Scripting

bash script working for small size files but not for big size files.

Hi, I have one file stat. Stat file contents are as follows: for example. H50768020040913,00260100,507680,13,0000000643,0000000643,00000,0000 H50769520040808,00260100,507695,13,0000000000,0000000000,00000,0000 H50770620040611,00260100,507706,13,0000000000,0000000000,00000,0000 Now i... (1 Reply)
Discussion started by: davidpreml
1 Replies

Featured Tech Videos