Commit 35d13b87 authored by thomas.forbriger's avatar thomas.forbriger

[FEATURE] (util): import shell script from BFO

csback_cscheck.sh
is designed to recurse into a subdirectory tree and to verify checksums
therein. It was originally created to check the LSDF archive.
parent 42753fdf
#!/bin/sh
# this is <csback_cscheck.sh>
# ----------------------------------------------------------------------------
# $Id: csback_cscheck.sh 1146 2015-02-05 20:14:52Z csanz $
#
# Copyright (c) 2013 by Thomas Forbriger (BFO Schiltach)
#
# passive check of csback checksums
#
# useful for checking external read-only copies of csback controlled data
# structures
#
# REVISIONS and CHANGES
# 09/04/2013 V1.0 Thomas Forbriger
# 16/12/2014 V1.1 Christopher Sanz add link to script cscomp.sh (line 36)
# 29/01/2014 V1.2 Christopher Sanz remove link to script cscomp.sh and include it in <csback_cscheck.sh>
#
# ============================================================================
#
SHABIN=/usr/bin/sha512sum
TMPDIR=$HOME/tmp/$0.$$
if test $# -lt 1
then
echo $0 takes a path name as a single argument
echo the path must point to the root of csback controlled data structure
exit 2
fi
DATADIR=$1
LOGLIST=
HERE=$(pwd)
nmcs=0 # counter for missing checksums
nmf=0 # counter for missing files
mkdir -p $TMPDIR
for FILE in $(find $DATADIR -name checksumfile.cs)
do
echo check $FILE
DIR=${FILE%/*}
cat $DIR/checksumfile.cs | cut -d' ' -f2 > $TMPDIR/chksm.tmp # write only filenames from checksumfile.cs in file
NLINES1=$(wc -l $TMPDIR/chksm.tmp | cut -d' ' -f1) # determine number of lines of chksm.tmp
#test1############## test if there is an entry in checksumfile.cs for every file
find $DIR -maxdepth 1 -type f -printf "%f\n" > $TMPDIR/lsfile.tmp #write the files of the directory in this file
NLINES2=$(wc -l $TMPDIR/lsfile.tmp | cut -d' ' -f1) # determine number of lines of lsfile.tmp
for ((line=1;line<=$NLINES2;line++))
do
FILECHECK=$(sed -ne ''$line'p' $TMPDIR/lsfile.tmp)
CHECK=$(cat $TMPDIR/chksm.tmp | grep -x $FILECHECK )
if [[ $CHECK != $FILECHECK ]] && [[ $FILECHECK != checksumfile.* ]] # test if there is an entry in checksumfile.cs for every file
then
echo $DIR/$FILECHECK has no entry in $DIR/checksumfile.cs
echo $DIR/$FILECHECK >> $TMPDIR/missingCS.log
echo $DIR/$FILECHECK has no entry in $DIR/checksumfile.cs >> $TMPDIR/cscompVerbose.log
nmcs=$((nmcs+1))
fi
nc=$((nc+1))
done
echo $nc files checked
echo $DIR checked, total $nc files checked >> $TMPDIR/cscompVerbose.log
unset NLINES2 CHECK FILECHECK DIR
#end#of#test1#######
NLINES=$(wc -l $FILE | cut -f 1 -d ' ')
if test $NLINES -gt 0
then
echo " check $NLINES entries"
cd $(dirname $FILE)
LOGFILE=$TMPDIR/$(echo $FILE | tr '/' '_')
cat $(basename $FILE) | tr -s ' ' | cut -f 1,2 -d ' ' \
| sed -e 's/ / /' | $SHABIN -c > $LOGFILE
LOGLIST+=" "$LOGFILE
else
echo " checksum file is empty"
fi
cd $HERE
done
rm $TMPDIR/lsfile.tmp $TMPDIR/chksm.tmp
echo "deviant results:"
egrep -v 'OK$' $LOGLIST
egrep -v 'OK$' $LOGLIST > $TMPDIR/deviant.log
echo $nmcs missing checksums in checksumfiles >> $TMPDIR/missingCS.log
echo list of missing checksums:
cat $TMPDIR/missingCS.log
echo "number of checked entries:" $(cat $LOGLIST | wc -l)
echo results are archived in $TMPDIR
# ----- END OF csback_cscheck.sh -----
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment