Changes between Version 2 and Version 3 of iniciando/manutencao


Ignore:
Timestamp:
05/21/09 15:43:47 (15 years ago)
Author:
rodsouza
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • iniciando/manutencao

    v2 v3  
    1010 
    1111É preciso fazer backup de todos os serviços, separadamente. É possível exportar os SQL com pg_dump, gerar ldif e fazer backup da pasta /var/spool/cyrus para os emails. Isso já garante boa parte do funcionamento do serviço. 
     12 
     13 
     14== Verificador de cota == 
     15 
     16Script Shell utilizado para verificar quais usuários estão com a cota acima de um determinado limiar. 
     17 
     18{{{ 
     19#!/bin/bash 
     20 
     21## 
     22# @AUTHOR Rodrigo Souza dos Santos 
     23# @DATE 2009/05/21 
     24# @BRIEF This script identifies users to share 
     25#        e-mail larger than a certain threshold 
     26#        and send an email to the administrator. 
     27## 
     28 
     29#/* foreground colors */ 
     30 
     31#define AFC_BLACK           30 
     32#define AFC_RED             31 
     33#define AFC_GREEN           32 
     34#define AFC_YELLOW          33 
     35#define AFC_BLUE            34 
     36#define AFC_MAGENTA         35 
     37#define AFC_CYAN            36 
     38#define AFC_WHITE           37 
     39 
     40#/* ansi background colors */ 
     41 
     42#define ABC_BLACK           40 
     43#define ABC_RED             41 
     44#define ABC_GREEN           42 
     45#define ABC_YELLOW          43 
     46#define ABC_BLUE            44 
     47#define ABC_MAGENTA         45 
     48#define ABC_CYAN            46 
     49#define ABC_WHITE           47 
     50 
     51# Função para imprimir colorido 
     52# $1 -> Número da cor do texto 
     53# $2 -> Número da cor de fundo 
     54# $3 -> Texto 
     55# $4 -> Imprimir na mesma linha, use -n 
     56 
     57DEBUG=1 
     58 
     59cecho(){ 
     60    if [ $DEBUG -gt 0 ] 
     61    then 
     62        echo ${4} -e "e[${1};${2}m${3}";tput sgr0; 
     63    fi 
     64} 
     65 
     66SENDMAIL=/usr/sbin/sendmail 
     67 
     68FROM="rodsouza@ecelepar10631" 
     69EMAILTARGET="rodsouza@ecelepar10631" 
     70SUBJECT="Cyrus Alert: Over Quota" 
     71 
     72# When DISPLAY_ALL is 0, only exceeded the quota 
     73# information will appear, if 1 then information 
     74# about all users will appear 
     75DISPLAY_ALL=0 
     76 
     77# default limit 
     78LIMIT=90 
     79 
     80# ensures that the argument is a number 
     81if ( echo ${1} | grep -E '^(*100|[0-9]{1,2})$' > /dev/null ) 
     82then 
     83    LIMIT=${1} 
     84fi 
     85 
     86clear 
     87 
     88CONTENT="" 
     89 
     90for i in a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y  z 
     91do 
     92    if [ -d "/var/lib/cyrus/quota/${i}" ] 
     93    then 
     94        for FILE in `ls -1 /var/lib/cyrus/quota/${i} | grep -E -v 'user.[^.]+.NEW$'` 
     95        do 
     96            USER=`echo ${FILE} | cut -c 6-`; 
     97            FILE="/var/lib/cyrus/quota/${i}/${FILE}" 
     98            QUOTA=`tail -n1 ${FILE}` 
     99            USAGE=`head -n1 ${FILE}` 
     100            PERCENT=`expr ${USAGE} / ${QUOTA}` 
     101            USAGE=$((USAGE/1024)) 
     102            let "PERCENT/=10" 
     103 
     104            echo 
     105            OUTPUT="${USER} 
     106        quota: ${QUOTA} MB 
     107        usage: ${USAGE} MB" 
     108            OUTPUT="${OUTPUT} 
     109        percent: ${PERCENT}%" 
     110 
     111            if [ ${PERCENT} -gt ${LIMIT} ] 
     112            then 
     113                # command to be executed when the quota is higher than desired. 
     114                OUTPUT="${OUTPUT} 
     115        quota is higher than ${LIMIT}%" 
     116 
     117                CONTENT="${CONTENT}The user "${USER}" is using ${PERCENT}%% of its quota. 
     118" 
     119                CONTENT=${CONTENT}"quota: ${QUOTA} 
     120usage: ${USAGE} 
     121 
     122" 
     123 
     124                #MSGDATE=`date +"%a, %e %Y %T %z"` 
     125 
     126                #MSG="Date: ${MSGDATE} 
     127From: ${FROM} 
     128To: ${EMAILTARGET} 
     129Subject: ${SUBJECT}" 
     130                #MSG=${MSG}" 
     131Mime-Version: 1.0 
     132X-Mailer: ExpressoMail 
     133 
     134${CONTENT}" 
     135 
     136                # send an email 
     137                #printf "${MSG}"  | ${SENDMAIL} -t 
     138 
     139                cecho 1 41 "${OUTPUT}" -n 
     140                echo 
     141            else 
     142                if [ $DISPLAY_ALL -gt 0 ] 
     143                then 
     144                    cecho 1 1 "${OUTPUT}" 
     145                fi 
     146            fi 
     147        done 
     148    fi 
     149done 
     150if [ ${#CONTENT} -gt 0 ] 
     151then 
     152    MSGDATE=`date +"%a, %e %Y %T %z"` 
     153 
     154    CONTENT="This alert is auto generated when a user exceeds ${LIMIT}%% of its quota. 
     155 
     156---- 
     157 
     158${CONTENT}" 
     159 
     160    MSG="Date: ${MSGDATE} 
     161From: ${FROM} 
     162To: ${EMAILTARGET} 
     163Subject: ${SUBJECT}" 
     164    MSG=${MSG}" 
     165Mime-Version: 1.0 
     166X-Mailer: ExpressoMail 
     167 
     168${CONTENT}" 
     169 
     170    # send an email 
     171    printf "${MSG}"  | ${SENDMAIL} -t 
     172fi 
     173}}}