Postfix - Listar usuários com over quota

Publicado por Thiago (última atualização em 29/05/2013)

[ Hits: 5.511 ]

Homepage: https://tamsti.wordpress.com/

Download Listar_Quota.sh




Exibir todos os usuários com over quota. No meu caso, os usuários localizados no diretório /home/remote/.

  



Esconder código-fonte

#!/bin/bash

#DefaultQuotaSize="50"

cd /home/remote/

function usage() {
        echo "Usage: $0 [options]"
        echo
        echo "-a|--all          Exibir todos usuarios com overquota"
        echo "-v|--verbose              Trabalha com -a e ainda exibe todos users/quota"
        echo "-u|--user <username>      Exibir apenas um usuario especifico."
        echo
        echo "Exemplo:  $0 --user username"
        echo "          $0 -a -v"
        exit 1
}

if [ $# -lt 1 ]; then
        usage
fi

# Setting default values
Verbose=0
ShowAll=0

while [ -n "$1" ]; do
        case "$1" in
                '-u'|'--user')
                        list="$2"
                        shift
                        ;;
                '-a'|'--all')
                        ShowAll=1
                        list='*'
                        ;;
                '-v'|'--verbose')
                        Verbose=1
                        ;;
                *)
                        usage
                        break
                        ;;
        esac
        shift
done

ReturnValue=0
for user in $(echo $list); do
        if [ -f ${user}/Maildir/maildirsize ]; then
                QuotaSize="$(sed -n '1s/S//p' ${user}/Maildir/maildirsize)"
                let QuotaSize/=1024*1024
                if [ "${QuotaSize}" == "" ]; then
                        QuotaSize=${DefaultQuotaSize}
                fi
                DiskUsage="$(sed -rn '2,$s/([-0-9]+) (.*$)/\1/p' ${user}/Maildir/maildirsize | paste -sd+ | bc)"
                let DiskUsage/=1024*1024
                if [ ${ShowAll} -eq 1 ]; then
                        if [ ${QuotaSize} -ne 0 ] && [ ${DiskUsage} -ge ${QuotaSize} ]; then
                                echo "User: $user - DiskUsage: ${DiskUsage}M - Quota: ${QuotaSize}M ### OVERQUOTA ###"
                        elif [ ${Verbose} -eq 1 ]; then
                                echo -n "User: $user - DiskUsage: ${DiskUsage}M - Quota: "
                                if [ ${QuotaSize} -eq 0 ]; then
                                        echo "UNLIMITED"
                                else
                                        echo "${QuotaSize}M"
                                fi
                        fi
                else
                        if [ ${QuotaSize} -ne 0 ] && [ ${DiskUsage} -ge ${QuotaSize} ]; then
                                echo "User: $user - DiskUsage: ${DiskUsage}M - Quota: ${QuotaSize}M ### OVERQUOTA ###"
                                ReturnValue=1
                        else
                                echo -n "User: $user - DiskUsage: ${DiskUsage}M - Quota: "
                                if [ ${QuotaSize} -eq 0 ]; then
                                        echo "UNLIMITED"
                                else
                                        echo "${QuotaSize}M"
                                fi
                        fi
                fi
        fi
done

exit ${ReturnValue}

Scripts recomendados

Ativando Numlock como serviço e no boot

Script de firewall

Fazendo Perguntas

Removendo kernels antigos no Ubuntu

Plugin do Nagios em Shell Script


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts