-
Notifications
You must be signed in to change notification settings - Fork 0
/
cksum_dir.sh
59 lines (53 loc) · 1.94 KB
/
cksum_dir.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# This script will scan all files in the whole directory including all files in all subdirectories
# to write its cksum in a new logfile named to match the acutal date+time under folder .cksum
# if logfolder+files are not already there, they will be created
#
#Usage
# cksum_dir.sh [comparelogfile]
#
#Parameter
# comparelogfile: Optinal Name of a logfile that is already there. Will Output differences in "diff"- Style
#
#Todos
# make more parameters
#
echo "==="
#set+create default logdir = ./.chksum
logdir="./.cksum"
if [ ! -d $logdir ] ; then
mkdir $logdir -v;
fi;
#set default logfile-name
datestr=$(date +%Y%m%d%H%M%S)
if [ ! $logfile ] ; then logfile="cksum_$datestr.log"; fi;
outfile=$logdir"/"$logfile
echo "Logfile to be used as output: "$outfile
#go and chksum directory-structure to logfile
cksumin=$(ls -ulaI$logdir) #Dont include the logdir as it will always be changed by this script
cksumout=$(echo $cksumin | cksum)
echo "CKSUM of Sourcedirectory (Listing): "$cksumout>$outfile
#now fetch all files...
echo "Fetching whole Filelist of Directory including Subdirs. Please be patient."
#create filelist in new file - needed while loop otherwise will not return anything back to this script (e.g. counters)
outpipe=$logdir"/cksum_filelist_$datestr.tmp"
find . -type f -not -path "./.cksum/*" -print0 | sort -z > $outpipe
counter=0;
while IFS= read -r -d $'\0' f; do
counter=$(($counter + 1));
done < $outpipe
#and output their cksum to logfile
echo "Processing $counter Files. You can get yourself some Coffee."
while IFS= read -r -d $'\0' f; do
cksumout=$(cksum "$f")
echo $cksumout>>$outfile
done < $outpipe
rm $outpipe
echo "Done CKSUMMing Files to Logfile."
#we are done if no compare arg $1 is given
if [ $1 ] ; then
echo "Now comparing current Logfile with $1. Each changed File will result in a single Line."
diff $logdir"/"$1 $outfile | grep "[>,<]"
fi;
echo "End of $0. You may delete Directory $logdir if not needed any more."
echo "==="