tags:

views:

48

answers:

1

Here's what I want to do:

I have thousand of split rar archives on folder name Archives. Name of the files 0001.part1.rar 0002.part2.rar 0003.part3.rar etc.

  1. read 0001.part1.rar
  2. create a directory based on prefix of the file above e.g. 0001
  3. move all files with the same prefix on the directory created above.
  4. Extract the files within that directory
  5. delete all rar files in that directory
  6. Rename the extracted file based on a list of names from a text file.
  7. Rar the renamed file with different arguments.
  8. Move the renamed file (from step 6) to a new directory called Done.
  9. Proceed to file 0002.part1.rar then do steps 2-8 and so forth.

Additional how would I incorporate it with cron??? This should be run once only...

After extracting the first set of rar's files change to:

file.001 
file.002 
file.003 

etc. which I need to extract too.

Clarification on Step 6:

After extracting the second set of rar's (file.001 , file.002 etc.) I want to rename it based on a list of names from a text file.

e.g. List of files from a text file:

0001 - GB Funds.DAT
0002 - US Bonds.DAT
0003 - SG Securities.DAT
0004 - LU Credits.DAT

Clarification on Step 7:

After renaming the file I want to move it on a new folder called "Done"

Clarification on Step 9:

Go back to the main folder with all the other archives 
and continue extracting the next set of archives and 
do the same steps from 1 to 8.
A: 

You can write a shell script including something like this:

# foo.sh
set -e
set -u

for i in `find -max-depth 1 -type f -name '*.rar' | sed 's/\.part*\.rar$//' | sort -u`; do
    mkdir $i
    mv $i.part*rar $i
    cd $i
    unrar x $i.part1.rar
    DST=`grep $i ../rename.txt | sed 's/^[0-9]\+ - //'`
    mv $i "$DST"
    # and so on, rar it together again, move it done directory etc.
    cd ..
done

Run it then via:

bash foo.sh

You have to clarify 6./8./9.

I don't know why do you want to run it via cron, since you only want to run it once. at is designed for running one-time jobs, or run it in a screen session.

I suggest that you do a few tests with 1-3 files from your collection and the script you end up with, before starting the whole job.

maxschlepzig
You will need to `cd` back to the parent directory or use `pushd`/`popd` (or a subshell).
Dennis Williamson
hi maxschlepzig I replied to your question. site does not allow long reply so I updated the main question above.
farneville
@Dennis Williamson: Since the script is just a scaffold, cd .. and other stuff was left out. @farneville: I updated my answer to show how to rename the extracted files.
maxschlepzig