Sponsored Content
Homework and Emergencies Emergency UNIX and Linux Support Script to fill the file system mount with empty files to desired size Post 302731331 by otheus on Wednesday 14th of November 2012 08:29:58 PM
Old 11-14-2012
Might be simpler to let awk do the calculation, and let the script's input parameters be used in the normal sense.
This code looks longer, because I added lots of checking, but the functional part is more concise.
Code:
usage() { 
  echo "Usage: $0 mountpoint threshold "
  echo "   where threshold is 1 to 100"
}

# $1 is the mountpoint
# $2 is the threshold (whole number, 1 to 100)

if [ ! -d $1 ]; then
  usage; exit 2;
fi
if [ $2 -lt 1 -o $2 -gt 100 ] ;then
  usage; exit 2;
fi

df -k $1 |
 awk -v t=$2     'NR==2  { print int($4 * (t-int($5))/100 ); }'  |
{
# The pipe-brace here in ksh isn't necessary, but in other sh-based shells, it is.
# 
read blocks
if [ -z $blocks -o $blocks -le 0 ] ; then
   echo "Error: Disk is already filled above threshold!"
   exit 1
else
   dd if=/dev/zero of=$1/.fillfile.$$ bs=1k count=$blocks
   exit $?
fi
}

I gave this a test under Darwin with bash.

You could make a really simple script with this:
Code:
df -k $1 |  awk -v t=$2  'NR==2  { print int($4 * (t-int($5))/100 ); }'  |
{ read blocks;  dd if=/dev/zero of=$1/.fillfile.$$ bs=1k count=$blocks }

If blocks is negative (your threshold is too low), dd will report an error. If it's 0, it will essentially do nothing (but still create the file).

You could do it for ALL mounted filesystems with this modification:
Code:
df -k |  awk -v t=$2  'NR>1  { print $NF,int($4 * (t-int($5))/100 ); }'  |
while read mountpoint blocks;  dd if=/dev/zero of=$mountpoint/.fillfile.$$ bs=1k count=$blocks ; done


Last edited by otheus; 11-14-2012 at 09:36 PM.. Reason: correction
This User Gave Thanks to otheus For This Post:
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
mount_xmemfs(1M)					  System Administration Commands					  mount_xmemfs(1M)

NAME
mount_xmemfs - mount xmemfs file systems SYNOPSIS
mount -F xmemfs [generic_options] -o[largebsize,]size=sz [-O] special mount_point DESCRIPTION
xmemfs is an extended memory file system which provides file system semantics to manage and access large amounts of physical memory which can exceed 4 GB in size. mount attaches a xmemfs file system to the file system hierarchy at the pathname location mount_point, which must already exist. If mount_point has any contents prior to the mount operation, these remain hidden until the file system is once again unmounted. The attributes (mode, owner, and group) of the root of the xmemfs filesystem are inherited from the underlying mount_point, provided that those attributes are determinable. If not, the root's attributes are set to their default values. The special argument is not currently used by xmemfs but a placeholder, (such as xmem), needs to be specified nevertheless. OPTIONS
See mount(1M) for the list of supported generic_options. -ospecific_options Specify xmemfs file system specific options in a comma-separated list with no intervening spaces. If invalid options are specified, a warning message is printed and the invalid options are ignored. The size=sz specific option is required. The following options are available: size=sz The sz argument specifies the desired size of this particular xmemfs file system. If the sz argu- ment has a k suffix, the number is interpreted as kilobytes. An m suffix is interpreted as megabytes and g is interpreted as gigabytes. A sz specified with no suffix is interpreted as bytes. In all cases, the actual size of the file system is the number of bytes specified, rounded up to the physical pagesize of the system or to the large page size if largebsize is specified. This specific_option is required. largebsize If largebsize is specified, xmemfs uses the large memory page size as the file system block size. On IA32, the large memory page size with mmu36 which supports PAE (Physical Address Extension) is 2 MB. The large memory page size without mmu36/PAE is 4 MB. If there is no large page support, the file system block size is PAGESIZE. -O Overlay mount. Allow the file system to be mounted over an existing mount point, making the underlying file system inaccessible. If a mount is attempted on a pre-existing mount point without setting this flag, the mount fails, producing the error device busy. FILES
/etc/mnttab table of mounted file systems ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ |ATTRIBUTE TYPE |ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |Architecture |i386 | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
mount(1M), mount(2), mkdir(2), open(2), umount(2), mnttab(4), attributes(5),xmemfs(7FS) NOTES
If the directory on which a file system is to be mounted is a symbolic link, the file system is mounted on the directory to which the sym- bolic link refers, rather than on top of the symbolic link itself. The only file types allowed on xmemfs are directories and regular files. The execution of object files resident in xmemfs is not supported. Execution is prevented by not allowing users to set execute permissions on regular files. SunOS 5.10 27 May 1999 mount_xmemfs(1M)
All times are GMT -4. The time now is 01:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy