2012年11月4日 星期日

Generate random files with random size using Bash

This file is copy from Internet, forgot where to get it already.

#!/bin/bash
# generate random files

if [ ! $# -gt 0 ]; then
   echo "usage: $0 <numfiles> [<blocksize> <maxblocks>]"
   echo " <numfiles>: number of files to create,"
   echo " <blocksize>: size of file blocks (default 1024 bytes)"
   echo " <maxblocks>: maximum number of blocks per file (default 100)"
   echo ""
   echo "Parameters after the third provided number are ignored."
   echo ""
   exit
fi

NUMFILES=$1
 

if test "$2" == ""; then
   BLOCKSIZE=1024
else
   BLOCKSIZE=$2
fi
 

echo Using blocksize $BLOCKSIZE

if test "$3" == ""; then
   MAXBLOCKS=100
else
   MAXBLOCKS=$3
fi
 

echo Using max blocks $MAXBLOCKS

for I in $(seq 1 $NUMFILES)
do
   echo $((($RANDOM % $MAXBLOCKS) +1))
   dd if=/dev/urandom of=testfile.$I.$RANDOM.bin bs=$BLOCKSIZE count=0      seek=$((($RANDOM % $MAXBLOCKS) + 1))
done

沒有留言: