Philip Dowie wrote:
if there is more than one rar file in $daydir, then you are going to run into problems - rarfile will be a space separated list of all the files, and the if will fail because of too many arguments.
Also, assuming there is no rar file, then $rarfile will be $daydir/*.rar (literal), so the test for its existance will fail, and rarfile will become either a) the name of the only .r01 file if there is only one b) space separated list of all the .r01 files (if there are more than one) c) $daydir/*.r01 (literal) if there are none.
You probably want something more like this:
for clientdir in /backup/*; do cd "${clientdir}" for daydir in "${clientdir}"/*; do for rarfile in "${daydir}"/*.{rar,r01}; do unrar x "${rarfile}" && rm -rf "${daydir}" done done done
This assumes that where you have .rar files and .r01 files, you want to unrar them both. If you want something else, then you'll need something different to check for both a .rar and a .r01 file.
Personally, I'd break out sed, but then the unnecessary-invocations-of-external-command police would scold me for not using the shell equivalent...
for clientdir in /backup/*; do cd "${clientdir}" for daydir in "${clientdir}"/*; do for rarfile in "${daydir}"/*.{rar,r01}; do rarname=`echo "${rarfile}" | sed -re 's/(.*)\.rar/\1/'` [ ! -e "${rarname}".r01 ] && unrar x "${rarfile}" && rm -rf "${daydir}" done done done
That will not unrar a rar file if a r01 file exists with the same first part of the name. but it is guilty of that unnecessary invocation of sed. something like
rarname="${rarfile/.rar/}".r01
might suit. BASH gurus will confirm or shoot me down..
Phil
Hi Phil, The files are multi-file spanned. Extracting the .rar file should extract all the rest of the .rxx files as they are in the chain listed in the first rar file. In some cases the starting rar is not a .rar but a .r01. Upon further reading the other way spanned rars can appear depending on the version of rar is that they may be named such as this as well: Filename.000.rar Filename.001.rar Filename.002.rar etc. -or- Filename.part01.rar Filename.part02.rar Filename.part03.rar Dean -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org