Determining exit codes for unrar (or alternative) in Bash
The background:
I'm clearing down an external drive for my mother-in-law which contains lots of downloaded cruft, including rars and their contents. I've used fslint to clear out temp files and times where the rar has been extracted multiple times (and in one case, 27 times!!) but I can't see an easy way to trap when a download has been extracted zero times. The best solution I can think of is to extract all of the rar files, fslint the drive again then bin off the rars entirely. The problem: What do I do with rar files that won't extract? I found this handy little script to test and rename them, but I'm having trouble discerning the difference between rar files that are actually corrupt and rar files that are passworded. To get the script to work, unrar needs to be passed the "-p-" flag, else it'll prompt for a password for every locked rar it finds (and this drive will have hundreds). I've confirmed that passing -p- to unrar for a passworded file always results in result code 3 (CRC Error). Any ideas on what I can do, or perhaps on a command line tool that can actually tell the difference? |
|
I did try p7zip, but the Diagnostics section of the man page shows nothing more concrete in error codes.
|
I guess then that expect should help you in this matter.
To recognize password protected rar files you should match a "Password:" line (IIRC) in unrar's output. |
I would rather delete all those files - in case they can be downloaded again
|
Expect looks like it might do what I want, but I think the expense of the effort might outweigh the gain. That said, I'm adding it to the list of things I need to learn. I worked around grep and sed for years, and now I've no idea how I lived without them! I'm going to use the script I linked to in the OP to rename all of the passworded files and move them away and leave them for the mum-in-law to deal with. I'm pretty sure that just with the non-passworded archives, I'll shave gigs and gigs from her drive.
Note to those in a similar boat who might later come across this: Copy the files to local storage first. Forgetting rar, even find is noticeably slower over USB! Thanks to all for the help :) |
All times are GMT -5. The time now is 03:25 PM. |