currently on my server, I have a directory containing several subdirectories. Each one of these subdirectories contains RAR files.

I'm looking for an automated way, if there is any, to UNRAR the files inside each folder, REPACK them to 200MB files, and then move those 200Mb files inside the root directory. So the process requires unraring, and possible waiting for it to finish, then raring again the extracted files, and then moving those files.

I don't know if this is possible, because of the intervals needed between each process.

If it's too difficult or impossible, I'd be also happy with a script which just PACKS each directory into 200mb files.

Maybe something like this... it's not tested at all so i don't promise anything about how it should work

Code:

#!/bin/bash# Translate argument 1 to usable nameinpath=$1# Save where you are right now.oldpwd=$(pwd)# Check if the directory in argument 1 exists.if [ -d $inpath ]; then cd $inpath; mkdir -p original; # Move the original files away, this will generate a warning since the "original" directory will be "moved" in this also. mv * $inpath/original &> /dev/null; mkdir -p $inpath/repacked; # Figure out which the first rar archive is, part01 or r00 versions doesn't matter that much. relname=$(ls $inpath/original/*.rar|head -n1); # Unpack it. unrar e -inul $relname $inpath/repacked; # If it fails, then exit if [ $? -eq 0 ]; then # Remove all the crap that we don't need and recreate it using our own standard. relname=$(basename $relname | sed -e "s/\(?:\.part01|.rar$\)//g"); # Our own standard (this is very possibly the same as one of the above, but since there's more then 1 option it's better to recreate it) outfile="$inpath/repacked/$relname.rar"; cd $inpath/repacked; # Pack the files into 200Mb files (-v200000k is for 200Mb noted in Kb) rar a -m0 -r -v200000k $outfile *; # If it succeds we move the files around to the right place if [ $? -eq 0]; then outpath="$inpath/repacked"; mv $outpath/* $inpath; # Delete the temporary "repacked" directory rm -rf $outpath; else echo "Failed to compress files... exiting..."; fi else echo "Failed to extract files ($relname).. exiting"; fifi# Return to where you started when executing the script.cd $oldpwd

It takes 1 argument as input, and that's the catalog that you're repacking.Usage: ./script.sh <path-to-catalog-which-contains-rar-files>

ps. This will keep the original release in a directory named "original", you'll have to delete that manually ds.

Actually, I don't want it to change anything in the original files in the subdirectory... I just want to have the same files, but extracted and repacked in 200MB in the root directory, so the whole moving part isn't needed.

#!/bin/bash# Translate argument 1 to usable nameinpath=$1# Save where you are right now.oldpwd=$(pwd)# Check if the directory in argument 1 exists.if [ -d $inpath ]; then cd $inpath; mkdir -p original; # Move the original files away, this will generate a warning since the "original" directory will be "moved" in this also. mv * $inpath/original &> /dev/null; mkdir -p $inpath/repacked; # Figure out which the first rar archive is, part01 or r00 versions doesn't matter that much. relname=$(ls $inpath/original/*.rar|head -n1); # Unpack it. unrar e -inul $relname $inpath/repacked; # If it fails, then exit if [ $? -eq 0 ]; then # Remove all the crap that we don't need and recreate it using our own standard. relname=$(basename $relname | sed -e "s/\(?:\.part01|.rar$\)//g"); # Our own standard (this is very possibly the same as one of the above, but since there's more then 1 option it's better to recreate it) outfile="$inpath/repacked/$relname.rar"; cd $inpath/repacked; # Pack the files into 200Mb files (-v200000k is for 200Mb noted in Kb) rar a -m0 -r -v200000k $outfile *; # If it succeds we move the files around to the right place if [ $? -eq 0 ]; then outpath="$inpath/repacked"; mv $outpath/* $inpath; # Delete the temporary "repacked" directory rm -rf $outpath; else echo "Failed to compress files... exiting..."; fi else echo "Failed to extract files ($relname).. exiting"; fifi# Return to where you started when executing the script.cd $oldpwd

I'm not sure I understand what it is you want.The original files are never changed, they're just moved to make room for the new files in the repacked catalog... which was supposed to be moved to the original location.

Anyway, the error was that a bracket (]) was against the 0 in "if [ $? -eq 0]"... bash doesn't like that.

What should happen now is the following:1) Enter the path you put in when starting the script.2) creates a "temporary" original directory3) moves the files from the "root" to the original directory4) creates a temporary directory named "repacked"5) unrar's the content from the "original" directory to the "repacked" directory6) if that went okey, then it figures out the name of the rar archive and repacks it in 200Mb files7) moves the newly created files in the "repacked" directory into the "root" directory (../ that is)

If you want to remove the original files then you can always add a "rm -rf original" at the bottom (above the "cd $oldpwd") and it'll be the last the script does.

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum