In Linux in Bash i have this script (thanks to Ed Morton) .
$ cat ./tst.sh #!/usr/bin/env bash while read -r idx sfx size; do echo fallocate "file${idx}.${sfx}" "$size" done < <( awk '{ for ( idx=1; idx<=NF; idx++ ) { remainSz = $idx chunkSz = 1000000000 if ( remainSz < chunkSz ) { chunkSz = 100000000 } sfx = 1 while ( remainSz > chunkSz ) { print idx, sfx++, chunkSz remainSz -= chunkSz } print idx, sfx, remainSz } }' "${@:--}" )
There is the file numbers_in_one_line
.
In this file there is only one line with several numbers, all separated by spaces.
These numbers are the value in bytes for creating files with the program fallocate.
The numbers are random and can change, in this example there are 4 numbers:
24997117901 4848337945 541113465 446445181
There can be sometimes more than 4 numbers.
By running the script, it do this:
$ ./tst.sh numbers_in_one_line fallocate file1.1 1000000000 fallocate file1.2 1000000000 fallocate file1.3 1000000000 fallocate file1.4 1000000000 fallocate file1.5 1000000000 fallocate file1.6 1000000000 fallocate file1.7 1000000000 fallocate file1.8 1000000000 fallocate file1.9 1000000000 fallocate file1.10 1000000000 fallocate file1.11 1000000000 fallocate file1.12 1000000000 fallocate file1.13 1000000000 fallocate file1.14 1000000000 fallocate file1.15 1000000000 fallocate file1.16 1000000000 fallocate file1.17 1000000000 fallocate file1.18 1000000000 fallocate file1.19 1000000000 fallocate file1.20 1000000000 fallocate file1.21 1000000000 fallocate file1.22 1000000000 fallocate file1.23 1000000000 fallocate file1.24 1000000000 fallocate file1.25 997117901 fallocate file2.1 1000000000 fallocate file2.2 1000000000 fallocate file2.3 1000000000 fallocate file2.4 1000000000 fallocate file2.5 848337945 fallocate file3.1 100000000 fallocate file3.2 100000000 fallocate file3.3 100000000 fallocate file3.4 100000000 fallocate file3.5 100000000 fallocate file3.6 41113465 fallocate file4.1 100000000 fallocate file4.2 100000000 fallocate file4.3 100000000 fallocate file4.4 100000000 fallocate file4.5 46445181
(I think it is nearly impossible that a file have the same size how the split size is. But If it so, it should not do anything, let a 1.000.000.000 byte file a 1.000.000.000 byte file.)
That works great for me, but i am looking for a way to incorporate some randomness.
if under 1GB do sometimes 100.000.000 or 104.857.600 or 50.000.000 or 52.428.800 over 1GB do sometimes 1.000.000.000 or 1.073.741.824 over 10GB do sometimes 1.000.000.000 or 1.073.741.824 or 500.000.000 or 524.288.000 over 50GB do sometimes 1.000.000.000 or 1.073.741.824 or 2.000.000.000 or 2.147.483.648 over 100GB do sometimes 1.000.000.000 or 1.073.741.824 or 2.000.000.000 or 2.147.483.648 or 5.000.000.000 or 5.242.880.000
Is is it too extensive or even better to bring this in a config file?!