#! /bin/csh -f # # check a written DVD/CD-R against the original filesystem # goto Setup Help: cat << EOF usage: verify.com /newdisk /directory [-delete] where: /newdisk - is the (removable) disk you want to check /directory - is the directory containing the original files -delete - implies to delete the files on disk once they are confirmed on the DVD -readthru - implies to keep going if a miscompare is found (default is to stop on first error) -random - implies to compare files in random order (default is the order found on the DVD) EOF exit 9 Setup: set tempfile = /tmp/verify_tmp$$ #set tempfile = tempfile if($#argv == 0) goto Help unsetenv DELETE unset DELETE set disk = "" set directory = "" set freed = 0 set bad_files = 0 set missing_files = 0 foreach arg ( $* ) if(-d $arg ) then if( ! -e "$disk") then set disk = "$arg" continue endif set directory = ( $directory $arg ) continue endif if ("$arg" == "delete") set DELETE if ("$arg" == "readthru") set READTHRU if ("$arg" == "random") set RANDOM if ("$arg" == "-delete") set DELETE if ("$arg" == "-readthru") set READTHRU if ("$arg" == "-regardless") set READTHRU if ("$arg" == "-random") set RANDOM end if (! -e "$disk") goto Help if ( ! -e "$directory") set directory = "/" if ( "$disk" !~ */ ) set disk = "${disk}/" if ( "$directory" !~ */ ) set directory = "${directory}/" again: if($?RANDOM) then set files = `find $disk -type f | awk '{print rand(),$NF}' | sort -n | awk '{print $NF}'` else set files = `find $disk -type f | awk '{++n;file[n]=$NF} END{for(;n>0;--n) print file[n]}'` endif if ($#files == 0 && ! $?tried_mount) then mount $disk set tried_mount goto again endif onintr report foreach file ( $files ) set basefile = `echo $disk $file | awk '{print substr($2,length($1)+1)}'` if(! -e "${directory}$basefile") then echo "warning: ${directory}$basefile unavailable..." @ missing_files = ( $missing_files + 1 ) set BAD = "missing files" if(! $?READTHRU) goto report continue endif echo -n "checking ${directory}$basefile on $disk ... " cmp $file ${directory}$basefile if($status) then # finish the printed line echo "BAD! " @ bad_files = ( $bad_files + 1 ) set BAD = "miscompare" if(! $?READTHRU) goto report continue endif echo "OK" # getting here implies the comparison went well if($?DELETE) then echo "deleting ${directory}$basefile" set size = `ls -ln ${directory}$basefile | awk '{print $5}'` set freed = `echo $freed $size | awk '{printf "%d",$1+$2}'` rm -f ${directory}$basefile endif end set FINISHED report: onintr if(! $?FINISHED) set BAD = "user interrupt" set ormore = "or more " if($?READTHRU && $?FINISHED) set ormore = "" if("$freed" != "0") then echo "$freed" | awk '{printf "freed %.1f MB\n",$1/1024/1024}' endif if("$bad_files" != "0") then echo "${bad_files} ${ormore}files did not match." endif if("$missing_files" != "0") then echo "${missing_files} ${ormore}files were not on disk." endif if ($#files == 0) then set BAD = "no files! " endif if ($?BAD) then echo "ERROR: $BAD" exit 9 endif exit