-4

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?!

6
  • 2
    Hi! Please ask a precise question, based on you trying to solve your problem at all. You already have someone else's code which you can build on – great, but we really don't want to become your free code writing service. The idea of us writing answers here is that you can do it yourself afterwards. That "afterwards" is now. I voted to close as "too broad". (this is your 49th question, not counting any (if any) deleted questions; I'm confident you can do at least a proper approach to this by now.)Commented22 hours ago
  • Note that I also think this should probably just be a clarifying edit to your previous question, unix.stackexchange.com/questions/794189/…Commented22 hours ago
  • (or if this is a new question, it's really not clear what is new about it.)Commented21 hours ago
  • @MarcusMüller the new part is "i am looking for a way to incorporate some randomness" but it's not clear what the OP means by that. They've also added some additional threshold values which I'd hope they could adapt the script I provided to handle by themselves before asking for help with "randomness".
    – Ed Morton
    Commented20 hours ago
  • Regarding "Is is it too extensive or even better to bring this in a config file?!" - no, to both questions but you need to clarify what it is you're trying to do (for example, does "sometimes" mean an even distribution between the subsequent values you list or something else? Are those values stored in a file or to be hard-coded or something else?) and provide concise, textual sample input/output we can copy/paste to test with.
    – Ed Morton
    Commented19 hours ago

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.