Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/sh
- # Variaveis manipulaveis
- #####################################
- V_Master="/var/log/asterisk/cdr-csv/Master.csv"
- V_extensions="/etc/asterisk/extensions.conf"
- V_dir_bkp="/etc/asterisk/bklog/"
- # Os prefixos devem ser separados com espaço
- #############################################
- V_tecprefix="310001 310002 310003 310004"
- V_pais="#55"
- # Dia inicial e final da pesquisa Master.csv
- # No exemplo abaixo começa no dia 20 do mês
- # anterior até o dia 19 do mês atual
- ##############################################
- V_diai="20"
- V_diaf="19"
- # Tempo sem segundos
- ##############################################
- V_limite="4560000"
- # E-mails de envio e destino para o alerta
- ##############################################
- V_mailfrom="seu@email.com.br"
- V_mailto="destino@email.com.br"
- # Variaveis sem ER
- #####################################
- V_data=`date +%Y%m%d`
- V_data_inicio=`date +%Y%m"${V_diaf}"`
- V_data_buscaf=`date +%Y-%m`
- V_data_buscai=`date -d "-1 month" +%Y-%m`
- V_nome=`uname -n`
- for V_linha in ${V_tecprefix}
- do
- # Variaveis sem ER
- #####################################
- V_bloqueio=""
- V_awk_busca="exten => _${V_linha}${V_pais}"
- V_trava=`grep "^; ${V_awk_busca}" "${V_extensions}"`
- # Variaveis com ER
- #####################################
- grep "${V_linha}" "${V_Master}" | sed "/${V_data_buscai}-${V_diai}/,/${V_data_buscaf}-${V_diaf}/!d" > "${V_dir_bkp}${V_linha}"
- V_contador=`egrep "${V_busca}" "${V_dir_bkp}${V_linha}" | awk -F"," '$15 !~ /"BUSY"|"NO ANSWER"/ {V_SOMA=V_SOMA+$15} END {print V_SOMA}'`
- [ ! "${V_contador}" ] && V_contador="0"
- V_conta_bkp=`ls "${V_dir_bkp}${V_linha}"* 2>/dev/null | awk 'END {printf "%04o", NR+1}'`
- gzip -S "_${V_conta_bkp}_${V_data}.gz" "${V_dir_bkp}${V_linha}"
- if [ \( "${V_data}" -eq "${V_data_inicio}" \) -a \( "${V_trava}" \) ]
- then
- V_conta_bkp=`ls "${V_dir_bkp}${V_extensions}_${V_data}_bkp.conf"* 2>/dev/null | awk 'END {printf "%04o", NR+1}'`
- cp "${V_extensions}" "${V_dir_bkp}extensions_${V_data}_bkp.conf"
- awk -v V_BUSCA="${V_awk_busca}" '{if ($0 ~ V_BUSCA) gsub (/; /, "")}; {print $0}' "${V_dir_bkp}extensions_${V_data}_bkp.conf" > "${V_extensions}"
- gzip -S "_${V_conta_bkp}.gz" "${V_dir_bkp}extensions_${V_data}_bkp.conf"
- V_bloqueio="Prefixo liberado"
- elif [ \( "${V_contador}" -ge "${V_limite}" \) -a \( ! "${V_trava}" \) ]
- then
- V_conta_bkp=`ls "${V_dir_bkp}${V_extensions}_${V_data}_bkp.conf"* 2>/dev/null | awk 'END {printf "%04o", NR+1}'`
- cp "${V_extensions}" "${V_dir_bkp}extensions_${V_data}_bkp.conf"
- awk -v V_BUSCA="${V_awk_busca}" '{if ($0 ~ V_BUSCA) sub (/e/, "; e")}; {print $0}' "${V_dir_bkp}extensions_${V_data}_bkp.conf" > "${V_extensions}"
- gzip -S "_${V_conta_bkp}.gz" "${V_dir_bkp}extensions_${V_data}_bkp.conf"
- V_bloqueio="Prefixo bloqueado"
- fi
- V_contador=`echo "${V_contador}" | awk 'SOMA = $1 / 60 {print SOMA}'`
- [ ! "${V_contador}" ] && V_contador="0"
- V_mensagem="${V_mensagem}
- Prefix ${V_linha} ja consumiu ${V_contador} min. ${V_bloqueio}
- "
- done
- # Envio de e-mail
- #############################
- (echo "HELO mail.seudominio.net";
- echo "AUTH LOGIN";
- # Seu login no padrão BASE64
- #############################################
- echo "fgsdfhljdhfshdfgsdlkjfghskdjfgklsdj==";
- # Sua senha no padrão BASE64
- #############################################
- echo "sdfhgdsifghsdfhgoshdg=";
- echo "MAIL FROM: ${V_mailfrom}";
- echo "RCPT TO: ${V_mailto}";
- echo "DATA";
- echo "FROM: ${V_mailfrom}";
- echo "SUBJECT: Consumo Prefixos servidor - ${V_nome}";
- echo "Content-type: text/plain; charset=ISO-8859-1; format=flowed";
- echo "";
- echo "Segue consumo em segundos dos prefixos";
- echo "${V_mensagem}";
- echo ".";
- echo "QUIT";) | nc -t mail.seudominio.net 25
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement