PABX da Simples IP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

68 lines
2.7 KiB

#!/bin/bash
EMAIL="suporte@simplesip.com.br"
SERVIDOR="algar.simplesip.com.br"
USUARIO="algar"
SENHA="@lgaR_SimpleS_2016"
REVENDA="..."
DIR_FTP="/hdaux/ftp/algar/audios/$REVENDA"
DIR_DESTINO="/hdaux/audio/$REVENDA"
[ -d /hd2 ] && DIR_DESTINO="/hd2/audio/$REVENDA"
/bin/rm -rf $DIR_DESTINO
DADOS=$(psql -Atc "select a.uniqueid, a.protoparceiro, b.userfield as arquivo_audio, b.data_bilhete, case when(length(a.protoparceiro) = 12)then 1 else 0 end as status_protocolo from pbx_protocolo_reg a, pbx_bilhetes b, pbx_classifica_reg c, pbx_classifica_atendimento d where b.uniqueid = a.uniqueid and c.id_bilhetes = a.uniqueid and d.clas_id = c.clas_id and a.protointegrado = 0 and d.clas_descricao = 'VENDA' and b.lastapp <> 'Transferred Call' and b.billsec > '0' order by b.data_bilhete" -d pbx)
[ -z "$DADOS" ] && exit
echo "$DADOS" > /tmp/dados_ftp_algar.txt
echo "$DADOS" | while read LINHA ; do
UNIQUEID=$(echo "$LINHA" | cut -f 1 -d "|")
PROTOCOLO_ALGAR=$(echo "$LINHA" | cut -f 2 -d "|")
AUDIO=$(echo "$LINHA" | cut -f 3 -d "|")
ANO=$(echo "$LINHA" | cut -f 4 -d "|" | cut -f 1 -d "-")
MES=$(echo "$LINHA" | cut -f 4 -d "|" | cut -f 2 -d "-")
DIA=$(echo "$LINHA" | cut -f 4 -d "|" | cut -f 3 -d "-")
STATUS_PROTOCOLO=$(echo "$LINHA" | cut -f 5 -d "|")
if ! [ -z "$AUDIO" ] ; then
if ! [ -d $DIR_DESTINO/$ANO ] ; then
mkdir -p $DIR_DESTINO/$ANO
fi
if ! [ -d $DIR_DESTINO/$ANO/$MES ] ; then
mkdir -p $DIR_DESTINO/$ANO/$MES
fi
if ! [ -d $DIR_DESTINO/$ANO/$MES/$DIA ] ; then
mkdir -p $DIR_DESTINO/$ANO/$MES/$DIA
fi
if [ "$STATUS_PROTOCOLO" == "1" ] ; then
/bin/cp -Rap /var/spool/asterisk/monitor/$AUDIO $DIR_DESTINO/$ANO/$MES/$DIA/${PROTOCOLO_ALGAR}_${UNIQUEID}.WAV
else
/bin/cp -Rap /var/spool/asterisk/monitor/$AUDIO $DIR_DESTINO/$ANO/$MES/$DIA/$AUDIO
psql -Atc "update pbx_protocolo_reg set protointegrado = '9' where uniqueid = '$UNIQUEID'" -d pbx
fi
fi
done
sshpass -p "$SENHA" rsync -zap --rsh="ssh -l algar -p 2223 -o StrictHostKeyChecking=no" $DIR_DESTINO/ $USUARIO@$SERVIDOR:$DIR_FTP
SSHPASSERROR=$?
if [ "$SSHPASSERROR" != "0" ] ; then
echo "ERRO: $(date +%F-%H-%M-%S) = $SSHPASSERROR" >> /tmp/sshpasserror.txt
echo -e "Subject: FALHA AO COPIAR AUDIO PARA O CLOUD - REVENDA:$REVENDA" | msmtp -t $EMAIL
else
cat /tmp/dados_ftp_algar.txt | while read LINHA ; do
UNIQUEID=$(echo "$LINHA" | cut -f 1 -d "|")
psql -Atc "update pbx_protocolo_reg set protointegrado = '1' where uniqueid = '$UNIQUEID' and protointegrado <> '9'" -d pbx
done
fi