Advertisement
fgvconsultoria

Sripts para o Asterisck

May 24th, 2013
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.95 KB | None | 0 0
  1. #! /bin/sh
  2.  
  3. # Variaveis manipulaveis
  4. #####################################
  5. V_Master="/var/log/asterisk/cdr-csv/Master.csv"
  6. V_extensions="/etc/asterisk/extensions.conf"
  7. V_dir_bkp="/etc/asterisk/bklog/"
  8. # Os prefixos devem ser separados com espaço
  9. #############################################
  10. V_tecprefix="310001 310002 310003 310004"
  11. V_pais="#55"
  12. # Dia inicial e final da pesquisa Master.csv
  13. # No exemplo abaixo começa no dia 20 do mês
  14. # anterior até o dia 19 do mês atual
  15. ##############################################
  16. V_diai="20"
  17. V_diaf="19"
  18. # Tempo sem segundos
  19. ##############################################
  20. V_limite="4560000"
  21. # E-mails de envio e destino para o alerta
  22. ##############################################
  23. V_mailfrom="seu@email.com.br"
  24. V_mailto="destino@email.com.br"
  25.  
  26. # Variaveis sem ER
  27. #####################################
  28. V_data=`date +%Y%m%d`
  29. V_data_inicio=`date +%Y%m"${V_diaf}"`
  30. V_data_buscaf=`date +%Y-%m`
  31. V_data_buscai=`date -d "-1 month" +%Y-%m`
  32. V_nome=`uname -n`
  33.  
  34. for V_linha in ${V_tecprefix}
  35. do
  36.         # Variaveis sem ER
  37.         #####################################
  38.         V_bloqueio=""
  39.         V_awk_busca="exten => _${V_linha}${V_pais}"
  40.         V_trava=`grep "^; ${V_awk_busca}" "${V_extensions}"`
  41.  
  42.         # Variaveis com ER
  43.         #####################################
  44.         grep "${V_linha}" "${V_Master}" | sed "/${V_data_buscai}-${V_diai}/,/${V_data_buscaf}-${V_diaf}/!d" > "${V_dir_bkp}${V_linha}"
  45.         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}'`
  46.         [ ! "${V_contador}" ] && V_contador="0"
  47.         V_conta_bkp=`ls "${V_dir_bkp}${V_linha}"* 2>/dev/null | awk 'END {printf "%04o", NR+1}'`
  48.         gzip -S "_${V_conta_bkp}_${V_data}.gz" "${V_dir_bkp}${V_linha}"
  49.  
  50.         if [ \( "${V_data}" -eq "${V_data_inicio}" \) -a \( "${V_trava}" \) ]
  51.         then
  52.                 V_conta_bkp=`ls "${V_dir_bkp}${V_extensions}_${V_data}_bkp.conf"* 2>/dev/null | awk 'END {printf "%04o", NR+1}'`
  53.                 cp "${V_extensions}" "${V_dir_bkp}extensions_${V_data}_bkp.conf"
  54.                 awk -v V_BUSCA="${V_awk_busca}" '{if ($0 ~ V_BUSCA) gsub (/; /, "")}; {print $0}' "${V_dir_bkp}extensions_${V_data}_bkp.conf" > "${V_extensions}"
  55.                 gzip -S "_${V_conta_bkp}.gz" "${V_dir_bkp}extensions_${V_data}_bkp.conf"
  56.                 V_bloqueio="Prefixo liberado"
  57.         elif [ \( "${V_contador}" -ge "${V_limite}" \) -a \( ! "${V_trava}" \) ]
  58.         then
  59.                 V_conta_bkp=`ls "${V_dir_bkp}${V_extensions}_${V_data}_bkp.conf"* 2>/dev/null | awk 'END {printf "%04o", NR+1}'`
  60.                 cp "${V_extensions}" "${V_dir_bkp}extensions_${V_data}_bkp.conf"
  61.                 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}"
  62.                 gzip -S "_${V_conta_bkp}.gz" "${V_dir_bkp}extensions_${V_data}_bkp.conf"
  63.                 V_bloqueio="Prefixo bloqueado"
  64.         fi
  65.         V_contador=`echo "${V_contador}" | awk 'SOMA = $1 / 60 {print SOMA}'`
  66.         [ ! "${V_contador}" ] && V_contador="0"
  67.         V_mensagem="${V_mensagem}
  68.        Prefix ${V_linha} ja consumiu ${V_contador} min. ${V_bloqueio}
  69.        "
  70. done
  71.  
  72. # Envio de e-mail
  73. #############################
  74. (echo "HELO mail.seudominio.net";
  75. echo "AUTH LOGIN";
  76. # Seu login no padrão BASE64
  77. #############################################
  78. echo "fgsdfhljdhfshdfgsdlkjfghskdjfgklsdj==";
  79. # Sua senha no padrão BASE64
  80. #############################################
  81. echo "sdfhgdsifghsdfhgoshdg=";
  82. echo "MAIL FROM: ${V_mailfrom}";
  83. echo "RCPT TO: ${V_mailto}";
  84. echo "DATA";
  85. echo "FROM: ${V_mailfrom}";
  86. echo "SUBJECT: Consumo Prefixos servidor - ${V_nome}";
  87. echo "Content-type: text/plain; charset=ISO-8859-1; format=flowed";
  88. echo "";
  89. echo "Segue consumo em segundos dos prefixos";
  90. echo "${V_mensagem}";
  91. echo ".";
  92. echo "QUIT";) | nc -t mail.seudominio.net 25
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement