#!/bin/bash # Purpose: # A crude test of file system integrity. # Developed it to detect faulty CDs. # Method: # Crawl the file system, starting in the current directory # and copy each file to /dev/null. Except in verbose mode # only I/O error messages will be shown on console. if [ x$1 = x-h ] || [ x$2 = x-h ] || [ x$3 = x-h ] || [ x$4 = x-h ] then echo " Usage: nullcheck [ -a -d -h -v ]" echo " -a include hidden files and directories" echo " -d dereference symlinks (to be implimented)" echo " -h print this message and exit" echo " -v verbose: explain what is being done (for debugging only)" echo exit 0 fi # Test for command line switches if [ x$1 = x-v ] || [ x$2 = x-v ] || [ x$3 = x-v ] then verbose=1 else verbose=0 fi export verbose if [ x$1 = x-a ] || [ x$2 = x-a ] || [ x$3 = x-a ] then list () { ls -A } else list () { ls } fi if [ x$1 = x-d ] || [ x$2 = x-d ] || [ x$3 = x-d ] then deref=1 else deref=0 fi export deref check () { for i in $(list) do if ( ! test -L "$i" ) || ( test $deref = 1 ) then if test -d "$i"; then if [ $verbose = 1 ] then echo "entering directory: $PWD/$i" fi cd "$i" check $* if [ $verbose = 1 ] then echo "leaving directory: $PWD" fi cd .. else if [ $verbose = 1 ] then echo "testing file: $PWD/$i" fi cp "$i" /dev/null; fi fi done } check