diff --git a/root/etc/cron.daily/samba-db-cleanup b/root/etc/cron.daily/samba-db-cleanup new file mode 100644 index 0000000..af1bac5 --- /dev/null +++ b/root/etc/cron.daily/samba-db-cleanup @@ -0,0 +1,13 @@ +#!/bin/bash + +LOG=$(/sbin/e-smith/db configuration getprop samba-db-logd status || echo 'disabled') + +if [ "$LOG" != "enabled" ]; then + exit 0 +fi + +RETENTION=$(/sbin/e-smith/db configuration getprop samba-db-logd Retention || echo 370) +DB=$(/sbin/e-smith/db configuration getprop samba-db-logd DbName || echo samba_log) + +echo "delete from audit where date_day/dev/null 2>&1 - - # Drop _0 table if we rotate more than two times a month - if echo "DESCRIBE ${T}_0;" | ${SQLCMD} >/dev/null 2>&1; then - echo "DROP TABLE ${T}_0;" | $SQLCMD - fi - - #compress 2 - cd /var/lib/mysql/${SQL_DB}/ - echo "FLUSH TABLE ${T}_${DATE};" | $SQLCMD - myisampack -s "${T}_${DATE}.MYI" - myisamchk -s -rq --sort-index --analyze "${T}_${DATE}.MYI" - echo "FLUSH TABLE ${T}_${DATE}" | $SQLCMD -done - -# Now check existing table to drop olds ones -for T in $(echo "show tables" | $SQLCMD | grep -v -P "^Tables_in_"$SQL_DB | grep -v -P "^audit$"); do - TMONTH=$(echo $T | perl -pe 'm/^audit_(\d+)_(\d+)/; print $1;exit') - TYEAR=$(echo $T | perl -pe 'm/^audit_(\d+)_(\d+)/; print $2;exit') - # Drop table if older than configured retention - if [ "$(($(date -d "01/$MONTH/$YEAR" +%s)-$(date -d "01/$TMONTH/$TYEAR" +%s)))" -gt "$((24*3600*$RETENTION))" ]; then - echo "DROP TABLE $T;" | $SQLCMD - fi -done - diff --git a/root/usr/bin/samba-db-logd b/root/usr/bin/samba-db-logd index db9970c..66391ad 100755 --- a/root/usr/bin/samba-db-logd +++ b/root/usr/bin/samba-db-logd @@ -97,7 +97,7 @@ while (defined(my $line=$tail->read)){ $action, $status, $access_mode, $file_src, $file_dst) = undef; # Oct 12 17:20:24 sme8 smbd[11176]: admin|192.168.7.50|pc10-45|intranet|mkdir|Nouveau dossier - if ($line =~ m/^\w+\s\d+\s\d+:\d+:\d+\s\w+\ssmbd\[\d+\]:\s+(\w+)\|(\d+\.\d+\.\d+\.\d+)\|([\w\.\-]+)\|(\w+)\|(\w+)/){ + if ($line =~ m/^\w+\s+\d+\s\d+:\d+:\d+\s\w+\ssmbd\[\d+\]:\s+(\w+)\|(\d+\.\d+\.\d+\.\d+)\|([\w\.\-]+)\|(\w+)\|(\w+)/){ $username = $1; $client_ip = $2; $client_name = $3;