-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdayumd5sum.sh
More file actions
executable file
·58 lines (51 loc) · 1.17 KB
/
dayumd5sum.sh
File metadata and controls
executable file
·58 lines (51 loc) · 1.17 KB
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
#!/bin/bash
# calculate md5sum from a list of file and store the result
function dayumd5sum {
local fname="$mntpnt/$1"
if [[ ! -e "$fname" ]];then
echo "$fname not exist." >>$logfile
fi
sum=$(md5sum "$fname"|awk '{print $1}')
if [[ $? -eq 0 ]];then
echo "$sum $1" >> $mlist
else
echo "$fname" >> $errlist
echo "$fname md5sum failed." >>$logfile
fi
}
function usage {
echo "Usage:bash `basename $0` -s ./filelist -m ./filelist.md5"
echo " -s source file list to do md5sum"
echo " -m result file of md5sum"
exit 0
}
mlist=./mlist
errlist=./errlist
mntpnt=/root
logfile=./md5sumlog
while getopts 's:m:h' OPT; do
case $OPT in
s)
slist=$OPTARG;;
m)
mlist=$OPTARG;;
h)
usage;;
esac
done
if [[ ! -f $slist ]];then
usage
fi
echo "$(date) start md5sum" >>$logfile
now=`date +%H`
deadtime=18
[ -f $mlist ] && mv $mlist "$mlist.$now"
[ -f $errlist ] && mv $errlist "$errlist.$now"
while read file
do
if [[ $now > $deadtime ]];then
echo "Time is up, end md5sum!" >>$logfile
exit 1
fi
dayumd5sum "$file"
done<$slist