We are regularly using for our testing, where we are manually filling up the mount with desired size with following command
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.
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)
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.
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
}