#!/usr/bin/php -q 7 and b.emp_id in(select min(emp_id) from vds_empresas where user_reg = 0 and length(emp_vpn) > 7 group by emp_vpn) and b.emp_ddd is null order by b.emp_id"; $resultAlgar = pg_query($connAlgar, $query); while ($dadosConexao = pg_fetch_array($resultAlgar)) { $empId = $dadosConexao["emp_id"]; $host = trim($dadosConexao["emp_vpn"]); $nome = trim($dadosConexao["emp_nome_fantasia"]); try { $conexaoVpn = pg_connect("host='{$host}' port='{$port}' dbname='{$dbname}' user='{$user}' password='{$password}' connect_timeout='5'", PGSQL_CONNECT_FORCE_NEW); if (!$conexaoVpn) { throw new Exception("Erro de conexao: {$nome} {$empId} Vpn: {$host}\n", true); } AtualizaDDD($conexaoVpn, $connAlgar, $empId); __Log("Revenda:{$nome} {$empId} Vpn: {$host} reprocessada!\n"); } catch (Exception $ex) { __Log(sprintf("Data: %s Cliente: %s %s Host: %s Msg: %s\n", date('Y-m-d H:i:s'), $nome, $empId, $host, $ex->getMessage())); } if ($conexaoVpn) { pg_close($conexaoVpn); } } //exec("chown -R algar:algar /hdaux"); __Log(sprintf("\nData: %s Operacao finalizada !!!!!\n", date("Y-m-d H:i:s"))); function __Log($log) { global $pathLog; if (!$pathLog) { $pathLog = '/var/log/asterisk/log_geral.log'; } $arq = fopen($pathLog, 'a'); fwrite($arq, $log); fclose($arq); } function AtualizaDDD($conexaoVpn, $connAlgar, $empId) { $query = "select prm_ddd_padrao from pbx_parametros"; if ($result = pg_query($conexaoVpn, $query)) { $row = pg_fetch_row($result); $dddPadrao = $row[0]; if ($dddPadrao) { $query = "update vds_empresas set emp_ddd = '{$dddPadrao}' where emp_id = '{$empId}'"; pg_query($connAlgar, $query); } } }