I have written a script to run ddrescue on a list of files.
#!/bin/bash
#
# A script to rescue data recursively using ddrescue.
srcDir=/damaged/hdd/movies/ #the source directory
desDir=/new/hdd/movies/ #the destination directory
workDir=/new/hdd/movies/ddrescue #location to store logs and working files
#preamble: I have already run rsync to copy files, but some failed part way through.
`rsync -rvn --size-only $srcDir* $desDir | sed "/speedup/d" | sed "/bytes\/sec/d" | sed "/sending\ incremental/d" | sed "/^$/d" > $workDir/work` #use rsync to generate list of partially transferred files.
workLength=`cat $workDir/work | wc -l` #Find number of files in list. For use with incrementing.
bookmark=0 #Begin at first entry in list.
while [ $bookmark -lt $workLength ]
do
bookmark=`expr $bookmark + 1` #increment through the list
currJob=`cat $workDir/work | sed -n ''$bookmark'p' | sed 's/\ /\\\ /g'` #extract nth filename from list, replace spaces with "\ "
echo "Start Rescue on " $currJob >> $workDir/runlog #
from=`echo $srcDir$currJob` #creates full filename for source file,
to=`echo $desDir$currJob` #destination file,
log=`echo $workDir/ddlog-$bookmark` #and ddrescue log file.
`ddrescue $from $to $log > $workDir/ddoutput-$bookmark` #run ddrescue, dumping output to file.
cat $workDir/ddoutput-$bookmark | grep -B 2 Finished | grep errors >> $workDir/runlog #read last 3 lines from ddrescue output and record it in runlog, so user can check which files are missing bits.
echo -e "\n"
done
exit
My problem is that ddrescue does not like the filenames I am giving it. If the filename has spaces in it it says
ddrescue: too many files
but if it has no spaces I get
ddrescue: cannot open input file: No such file or directory
I have tried using "quotes" instead of \'ing every space, but no luck. If I replace the command 'ddrescue' with 'echo', run the script, and then manually copy the given filenames into ddrescue in another terminal it works fine. But this rather defeats the purpose..
I have only been learning scripting for a little while, so I feel like I must be missing something obvious, I just can't figure out what!