Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a cron job which runs a script to unrar all files in a certain directory (/rared for argument's sake) and place the expanded files in /unrared. I would like to change this script so that it deletes the original rar archives from /rared only if they successfully extracted.

This does not mean that unrar has reported that they have been fully extracted, because I have had data corruption during decompression before.

Ideally (pie-in-the-sky, just to give you an idea of what I'm shooting for,) the unrar program would include this functionality, comparing an expected md5sum value with the actual md5sum value and only deleting the archive if they match. I don't mind scripting this entire process if I have to, but there must be a better way than unraring twice and comparing md5sums.

share|improve this question
    
Reposted as non-community-wiki (original deleted) –  Jeremy Oct 14 '10 at 5:57
    
I have a straaaange feeling I'm gonna have to offer a bounty on this one! But I'll lose the right to post bounties :/ #zerothworldproblems –  Jeremy Oct 14 '10 at 6:04
    
If unrar doesn't report data corruption, I'd rather check my disk/filesystem/memory for errors... –  JanC Oct 14 '10 at 15:05
    
It doesn't happen often (only seen it once or twice in years), but I don't want to risk losing a huge chunk of data because I didn't want to have to write a script to confirm that it extracted properly –  Jeremy Oct 14 '10 at 15:36
add comment

2 Answers 2

up vote 3 down vote accepted

A friend of mine has been working on a bash shell script to do this which is on github here.

https://github.com/arfoll/unrarall

share|improve this answer
    
Awesome, thanks man. I'll check it out. –  Jeremy Jan 11 '11 at 22:15
add comment

This is the script I have so far, it first checks if there is a current unrar operation running, and exits if there is (don't want to swamp the disk with heaps of read/writes). It then unRARs all files in /rared which have not already been unRARed, placing extracted files in /unrared. It does not yet check the extracted files or delete the archives:

[root@localhost rared]# cat unrarall 

#!/bin/sh

# First check if there is an "unrar" running already, if so, exit.

if ps -ef | grep -v grep | grep -v unrarall | grep unrar ; then
        exit 0
else

# This line probably unnecessary
PATH=$PATH:/usr/bin/


# The RARs I download are always multi-part, so I have to find the
#   first file in the archive and extract only that. This is done
#   using the "find" command. -exec means "run this command on the
#   file" and the filename is substituted wherever {} is 

find /rared/ -name "*part01.rar" -exec unrar -y -o- x \{\} /unrared/ \;
find /rared/ -name "*part001.rar" -exec unrar -y -o- x \{\} /unrared/ \;
find /rared/ -name "*.r00" -exec unrar -y -o- x \{\} /unrared \; 

# If you only want .rar files, comment out the above 3 lines and
#   uncomment the one below

# find /rared/ -name "*.rar" -exec unrar -y -o- x \{\} /unrared/ \;

fi

This is the crontab entry which accompanies it:

# m h dom mon dow   command
  * * *   *   *     rared/unrarall > /dev/null
share|improve this answer
    
Notes on unrar flags for anyone reading the script: "-y" means "answer yes to all questions" and "-o-" means "do not overwrite existing files when decompressing" –  Jeremy Oct 14 '10 at 6:05
    
Ok, so it turns out that unrar has a return code, which will at least tell me if all of the parts of the rar were present, and a file was extracted from them, if not getting me to the md5sum stage. I'll post an updated script when I've played around with $? –  Jeremy Oct 18 '10 at 12:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.