Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:bajizs_cnt:DBMail
dbmail2
dbmail-cleaning.cron
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File dbmail-cleaning.cron of Package dbmail2
#!/bin/bash # # Script for cleaning old messages form dbmail # # Copyright (c) 2009 Centar Novih Tehnlogija doo, Ruma, Serbia. # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place, Suite 330, Boston, MA 02111-1307 USA # # Author: Baji Zsolt <bajizs@cnt.rs> # # /etc/cron.daily/dbmail-cleaning # # The dbmail Configuration file CONFIG_FILE=/etc/dbmail.conf # Function: get_config_list config_file # Purpose : Print the list of configs from config file get_config_list() { typeset config_file=$1 awk -F '[][]' ' NF==3 && $0 ~ /^\[.*\]/ { print $2 } ' ${config_file} } # Function : set_config_vars config_file config [var_prefix] # Purpose : Set variables (optionaly prefixed by var_prefix) from config in config file set_config_vars() { typeset config_file=$1 typeset config=$2 typeset var_prefix=$3 typeset config_vars config_vars=$( awk -F= -v Config="${config}" -v Prefix="${var_prefix}" ' BEGIN { Config = toupper(Config); patternConfig = "\\[" Config "]"; } toupper($0) ~ patternConfig,(/\[/ && toupper($0) !~ patternConfig) { if (/\[/ || NF <2) next; if (/^#/) next; sub(/^[[:space:]]*/, ""); sub(/[[:space:]]*=[[:space:]]*/, "=\""); sub(/$/, "\""); print Prefix $0; } ' ${config_file} ) eval "${config_vars}" } # Set variables for all config from config file set_config_vars $CONFIG_FILE DBMAIL CFG_DBMAIL_ set_config_vars $CONFIG_FILE CLEANING CFG_CLEANING_ # cleaning dbmail database # first cleaning, if an error expected with sql, we have 24 hour tocorect it if [ "$CFG_CLEANING_UTIL_CLEANING" == "yes" ] then dbmail-util $CFG_CLEANING_UTIL_PARAMS fi if [ "$CFG_CLEANING_AUTO_CLEANING" == "no" ] then exit fi if [ "$CFG_DBMAIL_driver" == "mysql" ] then # building the query Q1=$(set | awk ' BEGIN { FS = "="; OS = " "; ORS = " OR "; i = 0; } { if ($0 !~ /^(CFG_CLEANING_FOLDER_|CFG_CLEANING_DAY_)/) next; sub(/^CFG_CLEANING_/, ""); if (/^FOLDER_/) { sub(/^FOLDER_/, ""); sub(/^\x27/, "", $2); sub(/\x27$/, "", $2); names[$1] = $2; } else { sub(/^DAY_/, ""); days[$1] = $2; } } END { for (x in names) if(days[x]) print "(dp.`internal_date` < DATE_SUB(NOW(), INTERVAL " days[x] " DAY) AND da.`name` = \"" names[x] "\")"; }' ) #execute the query mysql --host=$CFG_DBMAIL_host --user=$CFG_DBMAIL_user --password=$CFG_DBMAIL_pass --database=$CFG_DBMAIL_db --port=$CFG_DBMAIL_sqlport <<EOF START TRANSACTION; UPDATE ${CFG_DBMAIL_table_prefix}messages d, ${CFG_DBMAIL_table_prefix}mailboxes da, ${CFG_DBMAIL_table_prefix}physmessage dp SET d.status = 2 WHERE d.mailbox_idnr=da.mailbox_idnr AND d.physmessage_id=dp.id AND ( $Q1 0 ); COMMIT; EOF fi # end of mysql section
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor