Skip to content

Instantly share code, notes, and snippets.

@hlorand
Created January 29, 2018 18:27
Show Gist options
  • Select an option

  • Save hlorand/ae49fe50fc05acbd44f437f49ca98c19 to your computer and use it in GitHub Desktop.

Select an option

Save hlorand/ae49fe50fc05acbd44f437f49ca98c19 to your computer and use it in GitHub Desktop.
Caclucates and prints the md5 hash, sha1 hash and file modification date to a .txt file, separated by commas
#!/bin/bash
######################################
# Caclucates and prints the following data to a .txt file separated by commas;
# - MD5 hash
# - SHA1 hash
# - file modification date
# - filename
########################################
echo "A program kiszamolja az MD5, SHA1 hash-eit a fajloknak a mappaban es ezeket illetve a modositasi datumot egy .txt fajlba irja pontosvesszovel elvalasztva."
read -p "ENTER = START"
#vegigmegyek a fajlokon az aktualis mappaban
for file in $(dirname "$0")/**
do
#ez az mappak neveit is listazza csak akkor checksumolok ha file
if [ -f "$file" ]
then
#onmagat is listazza ezt kihagyom
if [ "$file" != "./checksum.sh" ]
then
MD5=$(md5 -q "$file")
SHA1=$(shasum -a 1 "$file" | awk '{print $1;}')
MODDATE=$(stat -f "%Sm" -t "%Y-%m-%d %H:%M" "$file")
FILENAME=$(basename "$file")
OUTPUT=$(echo $(basename "$PWD")_md5_sha1_moddate_at_$(date '+%Y-%m-%d').txt)
echo $MD5";"$SHA1";"$MODDATE";"$FILENAME >> $OUTPUT
echo $file
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment