I have one Folder receiving *.DAT file continuously every seconds. I want to split that folder into two folder where the parent(Folder which i want to split into two) folder will move all *.DAT file it receives in those two sub-folder in round robin fashion. Is there any way to do this by bash scripting?
There is your script:
#!/bin/bash # enter the source dir cd /tmp/a # set initial subdir subdir="b" # run forever while true do # get first available *.DAT file newfile=`ls -1 *.DAT 2>/dev/null | head -n1` if [ "$newfile" != "" ] then # if the .DAT file exists, move it mv ./$newfile /tmp/$subdir/ # replace subdir for next loop iteration if [ "$subdir" == "b" ] then subdir="c" else subdir="b" fi else # nothing found, wait 1 second sleep 1 fi done
I've used flat structure for testing
/tmp/a # source dir /tmp/b # destdir 1 /tmp/c # destdir 2
You'll have to modify it to your situation, but it should work.