burp_check_age: initial commit

This commit is contained in:
2020-06-29 09:28:52 +02:00
commit 4dae925030
2 changed files with 42 additions and 0 deletions

41
check_burp_age.sh Executable file
View File

@@ -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

1
user.list Normal file
View File

@@ -0,0 +1 @@
#backup directory;user email;backup max age