«

»

Duplicate random generated data in Linux based VM

A few weeks back i create a blog post about how to create random data in a Linux (CentOS) based VM which you can read here.  Based on that post i have received a few comments and one in particular i’ll address in this blog post and it was about the time it takes to generate the amount of data.

It will actually take quite some time but if you are good with generating a base file with random data and copy that file multiple times instead you can go ahead and use the script provided in this blog post instead.

You need to specify 4 things in the script:

  • logfile – full path to the log file destination including log file name
  • basefile – the file that will be created by the script from urandom and contain random data.
  • file copies – naming convention for the files created from the base file
  • numfiles – number of copies to be created.
  • filesize – the size of the base file
  • /datatest – directory specification

The script will create a base file including random data and then make as many copies of that file you specify.

Below is the scrip, creating 10 1GB files,  i used for some testing.

#/bin/sh
# Create one file from /dev/urandom and create multiple copies from the original file
# Author Magnus Andersson - Staff Solution Architect at Nutanix
# 2016-10-10
# Version 1.0
#
# Define logfile
logfile=/datatest/copyfiles.log
# Define the name of the base file to be created from /dev/urandom
basefile=urandombase.dat
# Define the name of the file copies to be created from $basefile
filecopies=urandombasecopy
# Define number of files to be copied
numfiles=10
# Define file size
filesize=1G
#
# Creating file via /dev/urandom
echo Script starting at $date > $logfile
echo Start creating the basefile $basefile from from /dev/urandom at: > $logfile
echo `date |awk '{print $4 " " $3 " " $2 " " $6}'` >> $logfile
echo Start creating the basefile @basefile from from /dev/urandom at:
echo `date |awk '{print $4 " " $3 " " $2 " " $6}'`
/bin/dd if=/dev/urandom of=/datatest/$basefile bs=$filesize count=1 &> /dev/null
echo
echo Done creating the $basefile file from /dev/urandom and now starting to create the copies >> $logfile
echo Done creating the $basefile file from /dev/urandom and now starting to create the copies
echo
for x in $(seq 1 $numfiles);do
/bin/cp /datatest/$basefile /datatest/$filecopies$x.dat &> /dev/null
echo done creating file copy $x
done
echo
echo Finished creating $numfiles files from $basefile at $date >> $logfile
echo `date |awk '{print $4 " " $3 " " $2 " " $6}'` >> $logfile
echo Finished creating $numfiles files from $basefile at:
echo `date |awk '{print $4 " " $3 " " $2 " " $6}'`

This is SSH session output when i ran the script in my test environment today, only creating 4 files.

screen-shot-2016-10-11-at-15-11-57