13/09/2005
crude script for sfv checking
Most of the times, when I download something and there’s an sfv file available I check the files against the sfv. That saves me from a lot of trouble later on…
What I wanted though, was to have the sfv check program create a dir inside each folder it checks that would include the details from the sfv scanning. That way you can instantly know whether what you have downloaded 1 week ago is ok, or there are bad files inside, or missing files. I sometimes used to check what I downloaded against the sfv file but I forgot to move it to my “complete” folder. So I made a VERY crude script that does exactly what I want. It uses pure-sfv (which I think is a bit faster than all the others I’ve tested) and then parses the output to create a dir that looks like this:
[ 49 OK, 0 BAD, 0 MISSING, OUT OF 49 ]
Here’s the script…
#!/bin/bash
THEOLDDIR=`ls -1 | grep "MISSING, OUT OF"` ; rm -rf "$THEOLDDIR"
ACTION=`pure-sfv *.sfv | egrep "different CRC|Tested|No such file" > check.tst`
THEBADONES=`grep different check.tst`
THEMISSONES=`grep "No such file" check.tst`
LINECOUNT=`wc -l check.tst | cut -d" " -f 1`
OKFILES=`tail -n1 check.tst | cut -d" " -f5 | cut -d"," -f1 `
BADFILES=`tail -n1 check.tst | cut -d" " -f7 | cut -d"," -f1 `
MISSFILES=`tail -n1 check.tst | cut -d" " -f9`
while read line ;do
BADIS=`echo $line | cut -d" " -f 1`
if [ $BADIS != "Tested" ]; then
if [ -e $BADIS ]; then
mv $BADIS $BADIS.bad
else
touch $BADIS.missing
fi
fi
done < check.tst
echo "$THEBADONES"
echo "$THEMISSONES"
echo "$OKFILES OK, $BADFILES BAD, $MISSFILES MISSING, OUT OF $[$OKFILES+$BADFILES+$MISSFILES]"
mkdir -p "[ $OKFILES OK, $BADFILES BAD, $MISSFILES MISSING, OUT OF $[$OKFILES+$BADFILES+$MISSFILES] ]" ; rm -f check.tst
USE IT AT YOUR OWN RISK!!! IT MAY DELETE ALL YOUR FILES. IT WON’T BE MY FAULT!
and yes I know the code sucks. If you don’t like it don’t use it.
Filed by kargig at 17:42 under Linux
No Comments | 2,802 views