script read burp client config file looking for warn and email parameter.
If present, it checks timestamp file and send an email if timestamp mtime is older than warn
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
#! /bin/bash
|
||||
|
||||
# param IN: csv file containing userdir,useremail,maxageofbackup in days
|
||||
# ex: /srv/burp/cafeine:thomas@foobar.org:4
|
||||
set -e
|
||||
set -u
|
||||
|
||||
# read burp client config files
|
||||
# if file include "warn", then check last backup date
|
||||
# if older than "warn" send message to "email"
|
||||
not_found=1
|
||||
too_old=2
|
||||
|
||||
list=$1
|
||||
if [ ! -r $list ] ; then
|
||||
echo "gimme a csv file"
|
||||
exit 5
|
||||
fi
|
||||
source <(grep clientconfdir /etc/burp/burp-server.conf | sed 's/ *= */=/g')
|
||||
|
||||
function mail_error {
|
||||
user=$1
|
||||
@@ -21,21 +20,42 @@ function mail_error {
|
||||
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
|
||||
echo -e "Bonjour,\n\nVotre poste n'a pas été sauvegardé depuis $fileage jours.\n\nPensez à laisser votre pc allumé et connecté ce soir, afin que la sauvegarde puisse se faire correctement. \n\nN'hésitez pas à me contacter si le problème persiste ou pour plus de renseignement.\n\n---\nThomas Constans\nthomas@opendoor.fr\n" | 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 ; }
|
||||
for file in $clientconfdir/* ; do
|
||||
if ( ! grep -q warn $file ) ; then continue ; fi
|
||||
if [ ! -f $file ] ; then continue ; fi
|
||||
maxage=$(awk -F= '/warn/{print $2}' $file)
|
||||
mail=$(awk -F= '/mail/{print $2}' $file)
|
||||
userdir=$(awk -F= '/directory/{print $2}' $file)
|
||||
userdir=${userdir}/$(basename $file)
|
||||
timestampfile=${userdir}/current/timestamp
|
||||
let "maxage=$maxage*86400"
|
||||
#test -r $timestampfile || { mail_error $mail $not_found ; continue ; }
|
||||
test -r $timestampfile || { echo $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
|
||||
|
||||
fileage=$( stat -c '%Y' $timestampfile)
|
||||
now=$(date "+%s")
|
||||
let "delta=$now-$fileage"
|
||||
if [ $delta -gt $maxage ] ; then
|
||||
echo $mail $too_old $(($delta/86400))
|
||||
mail_error $mail $too_old $(($delta/86400))
|
||||
fi
|
||||
done
|
||||
|
||||
#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
|
||||
Reference in New Issue
Block a user