lundi 30 juillet 2018

permission denied md5sum after if else comparison

i wrote a script, which finds all files in a directory and prints its phaths aswell as the md5 sum of a snippet of their head and tail to a txt file.

this works fine.

now i added an if-statement, so that if the filesize is less than 150000 bytes, it shall just calculate the md5sum of the whole file, without the head tail stuff.

this doesn't work and i dont know why. It gives me the error message:

/Users/Tobias/Desktop/Festplatten_indizieren_schleife.sh: line 16: ./.DS_Store: Permission denied

Here is the whole code:

echo Wie heißt die Festplatte? read varname echo Los gehts! 

before=$(date +%s)

IFS=$'\n' minimum=150000 for i in $( find . -type f ); do 
filsize=$( stat -f%z "$i" )     
if  ((filesize < minimum)); then
    both=$("$i" | md5)
else            
    h=$(head -c +51000 "$i" | tail -c 1000)
    t=$(tail -c 51000 "$i" | head -c 1000)

    both=$("$h$t" | md5)    
fi  
echo "$varname $i ; $both" >> /Users/Tobias/Desktop/$varname.txt;    

done

after=$(date +%s)

echo Das hat: $(((after - $before)/60)) Minuten bzw $(((after - $before))) Sekunden gedauert

I'm using Mac os 10.13.6

Note: I am doing this, because i collect all these data of 30 different external harddrives, so i can compare them and find dupikates. I am well aware that i am reinventing the wheel. BUT I can't use a program that finds duplikates etc... since these are 30 external harddrives

Anyway, if someone knows a better solution to find duplikates in 30 external harddrives, i will be the happiest person!

any help is appreciated

Aucun commentaire:

Enregistrer un commentaire