#!/bin/bash source /etc/nodemecu.conf source $funciones # Revisando stack for registro_json in $registros/*;do test "$registro_json" = "/opt/nodemecu/stack/\*" || break jsonlint-php $registro_json > /dev/null || mv -v $registro_json $registros_corruptos done while :;do # si no hay nada en el directorio registros reinicia el bucle # espera el intervalo definido o 1 minuto. file=$(get_stack) [ -z $file ] && sleep ${intervalo:-1}m && continue # si no respone el ping reinica el bucle ping -c 1 fsf.org > /dev/null 2>&1 || continue # si el fichero 'lock' existe (se esta creando un nuevo registro) reinicia el bucle [ -f $lock ] && continue # se testea que el servidor responda #test_url="$(curl -s -X POST -o /dev/null -w "%{http_code}" $servidor)" #if [ $test_url -eq 404 ];then # echo "$(date +%Y-%m-%d-%H:%M:%S) - $url - $test_url" >> /opt/nodemecu/errors.log && sleep 300 && continue #fi sing_file $registros/$file firma="$(cat $registros/$file.sign)" local_transaction_uuid=$(jq -r '."transaction_uuid"' $registros/$file) remote_transaction=$(curl -s --connect-timeout 0,9 --show-error -w "~%{http_code}" -X POST -H "X-Signature: $firma" -H "Content-Type: application/json" -d @$registros/$file $servidor 2> $curl_err) remote_response="$(echo $remote_transaction | cut -d '~' -f 1)" server_error="$(echo $remote_transaction | cut -d '~' -f 2)" if [ ${#remote_response} -eq 36 ];then if [ $local_transaction_uuid == $remote_response ]; then mv $registros/$file $historicos echo -e "$remote_response: \e[92mOK\e[0m" fi else echo -e "$local_transaction_uuid: \e[91mFAIL\e[0m" # errores unset srv_msg unset curl_msg err_time=$(date +%Y-%m-%d-%H:%M:%S) [ ! -z "$remote_response" ] && srv_msg="- $( echo $remote_response | grep -o '.*')" [ -s "$curl_err" ] && curl_msg="- $(> $log rm $curl_err fi done exit