A few weeks back i was asked by a customer to create a lot of random data in same amount of Linux (CentOS) based VMs as there were Nutanix nodes in their cluster.
I can see multiple reasons for doing this but that is a complete separate discussion, i just wanted to share the bash script i used in each VM after creating a 1 TB disk in each VM. There was some basic requirements such as:
- Logging start and complete time in the SSH session and to log file.
- Able to easily change
- file size
- number of files to be created
- file name
- /datatest – directory specification
Below is the scrip, creating 1000 1GB files, i was using to generate some data.
#/bin/sh # Create multiple files from /dev/urandom # Author Magnus Andersson - Staff Solution Architect at Nutanix # 2016-08-01 # # This section contains user defined variables # Define logfile logfile=/datatest/createfiles.log # Define the fixed part of the name of files to be created from /dev/urandom fixedname=urandomfile #Define number of files to be created numfiles=1000 # Define file size filesize=1G # End of user defined variables section # # Creating file via /dev/urandom echo Script starting at $date > $logfile echo Start creating $numfiles files from from /dev/urandom at > $logfile echo `date |awk '{print $4 " " $3 " " $2 " " $6}'` >> $logfile echo Start creating $numfiles files from from /dev/urandom at: echo `date |awk '{print $4 " " $3 " " $2 " " $6}'` echo for x in $(seq 1 $numfiles);do /bin/dd if=/dev/urandom of=/datatest/$fixedname$x.dat bs=$filesize count=1 &> /dev/null echo done creating file $x done echo echo Finished creating $numfiles files from /dev/urandom at >> $logfile echo `date |awk '{print $4 " " $3 " " $2 " " $6}'` >> $logfile echo Finished creating $numfiles files from /dev/urandom 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.
Another blog post with the same kind of topic is “Duplicate random generated data in Linux based VM” which is similar to this one but does not only generate random data. It will however, complete way faster and your file system will have a ton of data if you want.