From 4dae92503096bbcb22e1adb0870ca62b0e207858 Mon Sep 17 00:00:00 2001 From: Thomas Constans Date: Mon, 29 Jun 2020 09:28:52 +0200 Subject: [PATCH] burp_check_age: initial commit --- check_burp_age.sh | 41 +++++++++++++++++++++++++++++++++++++++++ user.list | 1 + 2 files changed, 42 insertions(+) create mode 100755 check_burp_age.sh create mode 100644 user.list diff --git a/check_burp_age.sh b/check_burp_age.sh new file mode 100755 index 0000000..11cf9ac --- /dev/null +++ b/check_burp_age.sh @@ -0,0 +1,41 @@ +#! /bin/bash + +# param IN: csv file containing userdir,useremail,maxageofbackup in days +# ex: /srv/burp/cafeine:thomas@foobar.org:4 +not_found=1 +too_old=2 + +list=$1 +if [ ! -r $list ] ; then + echo "gimme a csv file" + exit 5 +fi + +function mail_error { + user=$1 + code=$2 + fileage=$3 + case $code in + ($not_found): + echo "timestamp file for $user not found or not readable" | mail -s "backup error" rscj@opendoor.fr + exit $code + ;; + ($too_old): + echo -e "Pas de sauvegarde depuis $fileage jours.\n\nPensez a laisser votre pc connecte entre midi et 2, ou lancez une sauvegarde manuelle." | mail -s "Pb de sauvegarde" $user + esac +} + +IFS=\; +while read userdir mail maxage ; do + if [[ $userdir =~ ^# ]] ; then continue ; fi + timestampfile=${userdir}/current/timestamp + let "maxage=$maxage*86400" + test -r $timestampfile || { mail_error $mail $not_found ; continue ; } + + fileage=$( stat -c '%Y' $timestampfile) + now=$(date "+%s") + let "delta=$now-$fileage" + if [ $delta -gt $maxage ] ; then + echo $mail $too_old $(($delta/86400)) + fi +done < $1 \ No newline at end of file diff --git a/user.list b/user.list new file mode 100644 index 0000000..5929639 --- /dev/null +++ b/user.list @@ -0,0 +1 @@ +#backup directory;user email;backup max age