#!/bin/bash
#
#  A simple script that attemtpts to fill a disk with MD5sum-ed random-ish
#  data
#
#  Feedback to paulm@astro.gla.ac.uk  http://www.astro.gla.ac.uk/users/paulm


## Parameters
##
##    SIZE       how big a single file to create (in MegaBytes)
##    INIT_COUNT first counter index to start from
##    INCR_COUNT by how much to increment the counter each iteration
##    TARGET     directory in which to store all the files
##    MD5FILE    location of a file in which md5sums are stored.

SIZE=800
INIT_COUNT=1
INCR_COUNT=1
TARGET=/disk/raid0/root
MD5FILE=$TARGET/md5sums

## Odd numbers
#INIT_COUNT=1
#INCR_COUNT=2


##
## Leave alone from here on.
##

counter=${1:-$INIT_COUNT}


function calc_available() {
  export available=$(df -k $TARGET|tail -1 | awk '{print int($4/1024)}')
}

function build_file() {
  file="file$counter"
  md5sum=$(dd if=/dev/urandom bs=1M count=$SIZE 2>/dev/null | \
	tee $TARGET/$file | \
        md5sum | \
   	awk '{print $1}')
  echo "$md5sum  $file" >> $MD5FILE 
  counter=$[ $counter + ${1:-$INCR_COUNT} ]
}

calc_available
while [ $available -gt $SIZE ]; do
  echo Building $counter
  build_file
  calc_available
done

