mv load balance files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers mv load balance files
# 1  
Old 01-31-2008
mv load balance files

Ok so I have files that are going to land on /apps/, but I need to load balance them so I need to load balance them to four different folders.

The three file extensions I get are .mpe .mpd and mpf which will land here... /apps/ I can't move them until the mpf is there it triggers the next process within the ./a/ or. /b/ or. /c/ or ./d/ folder etc.

The names of the three files will be the same but I get three files for a file suite once they all land on the /apps/ dir I need to mv the file suite that's the oldest to

/apps/a/
/apps/b/
/apps/c/
/apps/d/


So for example filesuite1.mpe filesuite1.mpd and filesuite.mpf land on /apps/

So I need something that will pick them up each three and move to A then the next suite that comes in move to b and the next to C and so on ?

Last edited by xgringo; 01-31-2008 at 03:53 PM..
# 2  
Old 01-31-2008
#!/bin/bash
oldest_mpd=`ls -1 -t /apps/*.mpd | head -1`
oldest_mpe=`ls -1 -t /apps/*.mpe | head -1`
oldest_mpf=`ls -1 -t /apps/*.mpf | head -1`

mv $oldest_mpd /apps/d1/
mv $oldest_mpe /apps/d1/
mv $oldest_mpf /apps/d1/

mv $oldest_mpd /apps/d2/
mv $oldest_mpe /apps/d2/
mv $oldest_mpf /apps/d2/

mv $oldest_mpd /apps/d3/
mv $oldest_mpe /apps/d3/
mv $oldest_mpf /apps/d3/

mv $oldest_mpd /apps/d4/
mv $oldest_mpe /apps/d4/
mv $oldest_mpf /apps/d4/

I can put this into cron every minute right but I don't think this is going to be that fast, what if the moves happen in less than a minute and it moves four suites and then it's done til the next minute? Is there a way to make it continuous? will this work?

Would I have to do something like this to reload the variable again?

Last edited by xgringo; 01-31-2008 at 05:25 PM..
# 3  
Old 01-31-2008
The above is likely to produce errors as it assumes you'll have at least four sets of files in there any time it's run.

I'd think it would be better to leave something in memory instead. That way it will know where it last moved a file.
Code:
#!/bin/sh
TARGETLIST="a:b:c:d"
INTERVAL=60 # seconds

targetnum=1
targetlistsize=`echo $TARGETLIST | sed 's/[^:]//g' | wc -c`
while true
do
  for mpf in *.mpf
  do
    files="$mpf `echo $mpf | sed 's/f$/e/'` `echo $mpf | sed 's/f$/d/'`"
    if ls $files > /dev/null 2>&1
    then
      mv $files `echo $TARGETLIST | cut -d ':' -f $targetnum`
      targetnum=`expr $targetnum % $targetlistsize`
      targetnum=`expr $targetnum + 1`
    fi
  done
  sleep $INTERVAL
done

However, are you sure you are looking at the right problem? Could you not use a striped volume across those 4 devices instead?
# 4  
Old 01-31-2008
Thank you I'm going to try this out,

I am only an application administrator, so if I could design it perhaps we could do that, so I have to work around existing constraints.
# 5  
Old 01-31-2008
Could you also explain to me what this is doing?

files="$mpf `echo $mpf | sed 's/f$/e/'` `echo $mpf | sed 's/f$/d/'`"
# 6  
Old 01-31-2008
Quote:
Originally Posted by xgringo
Could you also explain to me what this is doing?
files="$mpf `echo $mpf | sed 's/f$/e/'` `echo $mpf | sed 's/f$/d/'`"
Sure, this creates a string containing the three files we're going to be moving in one set (blah.mpf, blah.mpd and blah.mpe).
You say that the .mpf generally arrives last so I'm looking for those to keep things efficient. This means that we start with all .mpf files and for each one, and generate a 3 element, space seperated list from it.
This is done by using sed to replace the last letter of the filename (ie 'f') with e in the second field and d in the third. The sed segments sare saying:
"take the .mpf filename, and look for a part of the name that has an 'f' followed by the end of line, then replace it with an e (or a d)".
# 7  
Old 01-31-2008
oh by the way, in case you hadn't spotted it, you can set the TARGETLIST variable at the top to be a : seperated list of directories, whatever and however many or few you wish (provided there's at least 1) and it should automatically figure out what to do.
INTERVAL is how many seconds to wait once it's processed all the files it's found this run before looking for more files. If it finds none it silently goes back to sleep for INTERVAL seconds again (you could set this to 1 if you want it to be highly responsive, or 300 to be pretty gentle on the system).
 
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Balance the load of files across queues using shell script

Hi, I need to balance the load to be processed by the system using shell script. The scenario is like below: Suppose there are some files in a directory: -rw-rw-r-- 1 usr usrgrp 456432306 Oct 23 07:53 abc_queue_q1 -rw-rw-r-- 1 usr usrgrp 4123934 Oct 23 07:53... (1 Reply)
Discussion started by: vsachan
1 Replies

2. Shell Programming and Scripting

Check value of load balance dynamically

Hi All, I want to check load balance(or CPU utilzation) on server dynamically based on that value i want to perform some operation . Means if load balance is <10 then start server . Am using prstat -a 1 commadn it is listing CPU utilzation/load balancing dynamically .. How to take this... (7 Replies)
Discussion started by: vivek1489
7 Replies

3. Linux

Load balance

Hello anybody know how use Load balance in linux? Summer (2 Replies)
Discussion started by: summerpeh
2 Replies

4. Shell Programming and Scripting

Need help in wrting Load Script for a Load-Resume type of load.

hi all need your help. I am wrting a script that will load data into the table. then on another load will append the data into the existing table. Regards Ankit (1 Reply)
Discussion started by: ankitgupta
1 Replies

5. UNIX for Dummies Questions & Answers

general ledger balance.

My general ledger account did not balance to my posting journal. How can I change the general ledger account to balance with my posting journal without having to post a one sided ticket and have it go to my outage account? :confused: (1 Reply)
Discussion started by: Jenny
1 Replies

6. UNIX for Dummies Questions & Answers

load Balance

Guys im trying to create a script that will load ballance 3 devices. Unix is still very alien to me having only been in this position for 3 months now. Not to mention the fact that i've been thrown in the deep end. Anyway so far i've managed to make a script that looks at all 4 devices and make a... (1 Reply)
Discussion started by: yorkyboy
1 Replies
Login or Register to Ask a Question