Link to home
Start Free TrialLog in
Avatar of Michael Smith
Michael SmithFlag for Ireland

asked on

I need to move folders from Source folder into 3 other folders in a "distributed even" way (Ubuntu Bash script)

I have 4 Directories

/DirectoryA
/DirectoryB
/DirectoryC
/DirectoryD

Through-out the day dozens of folders appear all containing data into DirectoryA - These folders will always have unique names......

I would like to run a script say every hour that would move all Folders (and there sub data) from DirectoryA into the other 3 Directory(B,C,D) so that there are an approximate equal amount of folders in each directory....

Example:
DirectoryA has 11 folders in it called 1-11 - All other Directories are empty.....

After script runs
Directory A is empty and
/DirectoryB has folder1, folder2. folder3, folder4       (4 folders total)
/DirectoryC has folder5, folder6. folder7, folder8       (4 folders total)
/DirectoryD folder9, folder10. folder11                        (3 folders total)

1 hour later.... (Before script is ran again)
Directoy A has 8 new folders in it - folders 12-20
/DirectoryB folder1, folder2. folder3, folder4             (4 folders total)
/DirectoryC has folder5,  folder8                               (2 folders total)
/DirectoryD Empty                                                     (0 folders total)

After Script runs
Directoy A is empty
/DirectoryB has  folder1, folder2. folder3, folder4, folder 12             (5 folders total)
/DirectoryC has folder5,  folder8,folder13,folder14                           (5 folders total)
/DirectoryD has folder15 folder16, folder17,folder18                        (4 folders total)

Not sure if i'm doing a good job of explaining  this  - just looking to distribute folders from a "source" folder into 3 other folders via a schedule.

Thanks for reading............
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michael Smith

ASKER

Noci - Fantastic work

I'm so impressed how quickly you can work out something that takes me days on end to complete (and usually fails)

Big Thanks

Absolutely perfect!!!
Avatar of noci
noci

If you have a problem  try to simplyfy .. forget about files/ folders...  
If you need visualisation try with scraps of papers and try to estimate what the real question is.....
Yours: an even spread over 3 directories... so Counting all objects is essential  and how they are spread...

Then try to implement a loop that moves all object to the right place.