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}\n\tquota: ${QUOTA} MB\n\tusage: ${USAGE} MB" 
     106            OUTPUT="${OUTPUT}\n\tpercent: ${PERCENT}%" 
     107 
     108            if [ ${PERCENT} -gt ${LIMIT} ] 
     109            then 
     110                # command to be executed when the quota is higher than desired. 
     111                OUTPUT="${OUTPUT}\n\tquota is higher than ${LIMIT}%" 
     112 
     113                CONTENT="${CONTENT}The user \"${USER}\" is using ${PERCENT}%% of its quota.\n" 
     114                CONTENT=${CONTENT}"quota: ${QUOTA}\nusage: ${USAGE}\n\n" 
     115 
     116                #MSGDATE=`date +"%a, %e %Y %T %z"` 
     117 
     118                #MSG="Date: ${MSGDATE}\nFrom: ${FROM}\nTo: ${EMAILTARGET}\nSubject: ${SUBJECT}" 
     119                #MSG=${MSG}"\nMime-Version: 1.0\nX-Mailer: ExpressoMail\n\n${CONTENT}" 
     120 
     121                # send an email 
     122                #printf "${MSG}"  | ${SENDMAIL} -t 
     123 
     124                cecho 1 41 "${OUTPUT}" -n 
     125                echo 
     126            else 
     127                if [ $DISPLAY_ALL -gt 0 ] 
     128                then 
     129                    cecho 1 1 "${OUTPUT}" 
     130                fi 
     131            fi 
     132        done 
     133    fi 
     134done 
     135if [ ${#CONTENT} -gt 0 ] 
     136then 
     137    MSGDATE=`date +"%a, %e %Y %T %z"` 
     138 
     139    CONTENT="This alert is auto generated when a user exceeds ${LIMIT}%% of its quota.\n\n----\n\n${CONTENT}" 
     140 
     141    MSG="Date: ${MSGDATE}\nFrom: ${FROM}\nTo: ${EMAILTARGET}\nSubject: ${SUBJECT}" 
     142    MSG=${MSG}"\nMime-Version: 1.0\nX-Mailer: ExpressoMail\n\n${CONTENT}" 
     143 
     144    # send an email 
     145    printf "${MSG}"  | ${SENDMAIL} -t 
     146fi 
     147}}}