md5_cp/calc_md5.sh

54 lines
1010 B
Bash
Raw Normal View History

2019-03-05 16:40:59 +00:00
#!/bin/bash
2019-09-10 23:30:58 +00:00
folder="/mnt/export/transport"
md5="md5.txt"
## prepare
cat "${md5}" > "${md5}.bak"
2019-09-10 23:20:43 +00:00
md5_tmp=`mktemp`
2019-09-10 23:30:58 +00:00
md5_add="${md5}.add"
2019-03-05 16:40:59 +00:00
#sort & del dublicates
2019-09-10 23:30:58 +00:00
sed -i '/^$/d' "$md5"
cat "$md5" | sort -k 2 | uniq > "$md5_tmp"
cat "$md5_tmp" > "$md5"
2019-03-05 16:40:59 +00:00
2019-09-10 23:20:43 +00:00
cat $md5_tmp | while read line; do
2019-03-05 16:40:59 +00:00
#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"
2019-09-10 23:30:58 +00:00
sed -i "/$md5/d" "$md5"
2019-03-05 16:40:59 +00:00
fi
done
#search for new files
2019-09-10 23:30:58 +00:00
find "$folder" -type f | grep -v "/.Trash-" | sort | while read line; do
2019-03-05 16:40:59 +00:00
#save fiel path
2019-09-10 23:30:58 +00:00
result=$(grep "$line" "$md5"); [ -z "$result" ] && {
2019-03-05 16:40:59 +00:00
#wenn kein eintrag in liste...
echo "new $line"
2019-09-10 23:30:58 +00:00
md5sum "$line" >> "$md5_add"
2019-03-05 16:40:59 +00:00
}
done
2019-09-10 23:30:58 +00:00
[ -f "$md5_add" ] && {
cat "$md5_add" >> "$md5"
rm "$md5_add"
2019-03-05 16:40:59 +00:00
}
#sort & del dublicates
2019-09-10 23:30:58 +00:00
cat "$md5" | sort -k 2 | uniq > $md5_tmp
rm "$md5" && mv $md5_tmp "$md5"
## diff
diff "${md5}" "${md5}.bak"