writing files to a dir in round robin order


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting writing files to a dir in round robin order
# 1  
Old 03-09-2007
writing files to a dir in round robin order

I have a list of directories. (say a1,a2,a3,a4,a5)
I need to get the directory last modified and access the next one to put some files over there (say if a3 is the latest dir modified ie, last time files were put into a3, this time I need to move the files in a4)...and if a5 is the last modified dir, I need to move the files in a1. thus it works in a round robin manner. Can u pls suggest how do I achieve this ?
# 2  
Old 03-09-2007
try this,

Code:
val=`/usr/bin/ls -1rtF | sed -n "/\/$/p" | sed -n '$p' | sed "s/[A-Za-z/]//g"`
if [ $val eq 5 ]
then
 newval=1
else
 newval = $(($val + 1))
fi
echo "your new dir is a$newval"

not optimised! Smilie
# 3  
Old 03-09-2007
Oops !!! A small mistake on my side :-( ...all these dir names are configurable...instead of a1...a5, they can be anything, (say abc,mnp,xyz) ...so the logic doesn't work...any alternative ?
# 4  
Old 03-09-2007
Quote:
Originally Posted by kanchan_cp
Oops !!! A small mistake on my side :-( ...all these dir names are configurable...instead of a1...a5, they can be anything, (say abc,mnp,xyz) ...so the logic doesn't work...any alternative ?

If not a1 ... a5

how do you maintain the order ?

Like, how do you determine which should go first, next ?

If you maintain the order somewhere ( like that in a configuration file ), we could retrieve based on that.

Could you please provide some more input on that ? Smilie
# 5  
Old 03-09-2007
last_modified_dir=`ls -ltu | grep ^d | awk '{print $NF}' | sed -n 1p`
files_to_be_moved_to=`ls -ltu | grep ^d | awk '{print $NF}' | sed -n 2p`
# 6  
Old 03-09-2007
if you have Python, here's an alternative
Code:
import os,shutil
rootdir = "/home/test"
os.chdir(rootdir)
store={} #store directories' access times
directories = ['a1','a2','a3','a4','a5'] #configure directories here
dirchange = { 'a1' : 'a2' , 'a2':'a3', 'a3':'a4' , 'a4':'a5','a5':'a1' }
for d in directories:
    store[os.stat(d)[8] ] = d
latesttime = reversed(sorted(store.keys())).next()
latestdir = store[latesttime]
os.chdir(latestdir)
for file in os.listdir('.'):
    shutil.move(file, os.path.join(rootdir, dirchange[latestdir]))

# 7  
Old 03-12-2007
Quote:
Originally Posted by matrixmadhan
If not a1 ... a5

how do you maintain the order ?

Like, how do you determine which should go first, next ?

If you maintain the order somewhere ( like that in a configuration file ), we could retrieve based on that.

Could you please provide some more input on that ? Smilie

yes, from the config file i ll get a comma separated list of directory names. We need to start with the first one in the list and go on...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

Help- writing to dir with no write permissions (script)

hello, I have a question regarding the below script.. I just simply trying to write to a file in directory that does not have write permissions but this is failing .. it still writes to it regardless .. Many thanks in advance.. #!/bin/bash #check if dir exists, if so write to it ... (5 Replies)
Discussion started by: Reb0rn
5 Replies

3. Programming

Round Robin Scheduling via UCONTEXT.H

Hi I am implementing Round Robin Scheduling using ucontext.h functions. Well i am using my own logic for round robin but i am stuck at one point. I am using swapcontext for shifting from one process to another. Now how do i get to know that after 4 sec(Round Robin Time) where the process has... (1 Reply)
Discussion started by: aditya08
1 Replies

4. UNIX for Dummies Questions & Answers

Round Robin Algorithm

Hey, guys I have a task: Job Running time Priority A 10 3 B 6 5 C 2 2 D 4 1 E 8 4 All 5 jobs have the same arrival time. The question is, what is the average waiting time according to Round Robin algorithm. Quantum = 1 min. The answer that was given by a... (1 Reply)
Discussion started by: Anne_Stark
1 Replies

5. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

6. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

7. Shell Programming and Scripting

help writing rm script excluding specific titled dir

I am attempting to write a housecleaning script that does the following: 1) goes to a specific directory 2) deletes all contents of that directory but a specific directory within it. So my users all keep and use the Shared directory in OSX. Within /Users/Shared there are also standard named... (1 Reply)
Discussion started by: nomados
1 Replies

8. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

9. Shell Programming and Scripting

Round Robin Distribution of Contents of file to 3 files

Hi I need to create a script that distributes in round robin fashion the contents of a file to 3 files. The number of lines in a content of file can vary from 1-n(Each line is just a one letter word).The entire lines needs to get distributed into 3 files ( The order doesnt matter) , at... (5 Replies)
Discussion started by: police
5 Replies

10. UNIX for Advanced & Expert Users

Round Robin Scheduling

Hi, first post. Well, here goes: Ok, so I need to build a round robin scheduling algorithm. I understand HOW the algorithm works and I can write it down/show you on paper if you were to ask me "how does the RR scheduling algorithm work?" Only problem is that I'm having a hell of a time... (0 Replies)
Discussion started by: ramoneguru
0 Replies
Login or Register to Ask a Question