2022-03-05 18:13:50 +00:00
|
|
|
#!/bin/bash
|
|
|
|
source /etc/nodemecu.conf
|
2022-03-11 02:00:35 +00:00
|
|
|
source $funciones
|
2022-03-05 18:13:50 +00:00
|
|
|
|
|
|
|
|
2022-03-11 02:00:35 +00:00
|
|
|
# Revisando stack
|
2022-03-05 18:13:50 +00:00
|
|
|
|
2022-03-11 02:00:35 +00:00
|
|
|
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
|
2022-03-05 18:13:50 +00:00
|
|
|
done
|
|
|
|
|
2022-03-11 02:00:35 +00:00
|
|
|
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
|
2022-03-05 18:13:50 +00:00
|
|
|
|
2022-03-11 02:00:35 +00:00
|
|
|
# si no respone el ping reinica el bucle
|
|
|
|
ping -c 1 fsf.org > /dev/null 2>&1 || continue
|
2022-03-05 18:13:50 +00:00
|
|
|
|
2022-03-11 02:00:35 +00:00
|
|
|
# si el fichero 'lock' existe (se esta creando un nuevo registro) reinicia el bucle
|
|
|
|
[ -f $lock ] && continue
|
2022-03-05 18:13:50 +00:00
|
|
|
|
|
|
|
|
2022-03-11 02:00:35 +00:00
|
|
|
# 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
|
2022-03-05 18:13:50 +00:00
|
|
|
|
|
|
|
|
2022-03-11 02:00:35 +00:00
|
|
|
sing_file $registros/$file
|
|
|
|
firma="$(cat $registros/$file.sign)"
|
|
|
|
|
2022-03-05 18:13:50 +00:00
|
|
|
|
|
|
|
|
2022-03-11 02:00:35 +00:00
|
|
|
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
|
2022-03-05 18:13:50 +00:00
|
|
|
|
2022-03-11 02:00:35 +00:00
|
|
|
if [ $local_transaction_uuid == $remote_response ]; then
|
|
|
|
mv $registros/$file $historicos
|
|
|
|
echo -e "$remote_response: \e[92mOK\e[0m"
|
|
|
|
fi
|
2022-03-05 18:13:50 +00:00
|
|
|
else
|
2022-03-11 02:00:35 +00:00
|
|
|
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 '<body.*>.*</body>')"
|
|
|
|
[ -s "$curl_err" ] && curl_msg="- $(</tmp/curl_err)"
|
|
|
|
echo $err_time - $local_transaction_uuid - server status: $server_error $srv_msg $curl_msg >> $log
|
|
|
|
rm $curl_err
|
2022-03-05 18:13:50 +00:00
|
|
|
fi
|
2022-03-11 02:00:35 +00:00
|
|
|
|
|
|
|
done
|
|
|
|
exit
|
2022-03-05 18:13:50 +00:00
|
|
|
|