md5_cp/calc_md5.sh
2019-09-11 01:30:58 +02:00

54 lines
1010 B
Bash
Executable File

#!/bin/bash
folder="/mnt/export/transport"
md5="md5.txt"
## prepare
cat "${md5}" > "${md5}.bak"
md5_tmp=`mktemp`
md5_add="${md5}.add"
#sort & del dublicates
sed -i '/^$/d' "$md5"
cat "$md5" | sort -k 2 | uniq > "$md5_tmp"
cat "$md5_tmp" > "$md5"
cat $md5_tmp | while read line; do
#get md5
md5=$(echo $line | cut -c -32)
#get path of file
file=$( echo $line | cut -c 34-)
#wenn datei existiert
if [ -f "$file" ]; then
# do nothing
echo > /dev/null
else
echo "rm $line"
sed -i "/$md5/d" "$md5"
fi
done
#search for new files
find "$folder" -type f | grep -v "/.Trash-" | sort | while read line; do
#save fiel path
result=$(grep "$line" "$md5"); [ -z "$result" ] && {
#wenn kein eintrag in liste...
echo "new $line"
md5sum "$line" >> "$md5_add"
}
done
[ -f "$md5_add" ] && {
cat "$md5_add" >> "$md5"
rm "$md5_add"
}
#sort & del dublicates
cat "$md5" | sort -k 2 | uniq > $md5_tmp
rm "$md5" && mv $md5_tmp "$md5"
## diff
diff "${md5}" "${md5}.bak"