aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvg <vg@devys.org>2018-01-14 10:42:46 +0100
committervg <vg@devys.org>2018-01-14 10:42:46 +0100
commitf5bba3428170f2e992f5d79fa88ff92f8698c885 (patch)
treedb78a751390c5693d71cc851295acc15eba09298
parenta55623c983225f381e1dad27cbc60c8c0ab1574c (diff)
downloadscripts-f5bba3428170f2e992f5d79fa88ff92f8698c885.tar.gz
scripts-f5bba3428170f2e992f5d79fa88ff92f8698c885.tar.bz2
scripts-f5bba3428170f2e992f5d79fa88ff92f8698c885.zip
add a script checking regularly (cron) integrity of files
-rwxr-xr-xscripts/files_integrity_croncheck.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/files_integrity_croncheck.sh b/scripts/files_integrity_croncheck.sh
new file mode 100755
index 0000000..0cf99d8
--- /dev/null
+++ b/scripts/files_integrity_croncheck.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+set -eu
+
+mail='user@example.com'
+output_dir='/tmp/md5sums'
+dirs=(
+ "$HOME/todo"
+ #/exemples/to/monitor
+)
+
+diff_two_last_by_mail()
+{
+ if [ $# -lt 2 ]; then
+ return # nothing to done then not at least two files to compare
+ fi
+
+ diff -u <(zcat "$1") <(zcat "$2") \
+ | ifne mail -s "Changes in md5sums between $1 and $2" "$mail"
+}
+
+mkdir -p "$output_dir"
+for dir in "${dirs[@]}"; do
+ basefn="$(printf "%s\n" "$dir" | sed 's:/:_:g;s/^_//;s/_$//')"
+ outputfn="$output_dir/${basefn}_$(date +%F_%T).md5sum.gz"
+
+ find "$dir"/ -type f -print0 | sort -z | xargs -0 md5sum -b \
+ | gzip -9 > "$outputfn"
+
+ diff_two_last_by_mail \
+ $(find "$output_dir"/ -name "${basefn}*.md5sum.gz" | sort | tail -n 2)
+done