From dd48575a1b0e761c265deeb052c261b34fe0b10d Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:11:32 -0300 Subject: [PATCH 01/21] =?UTF-8?q?no=20hardcodear=20el=20directorio=20de=20?= =?UTF-8?q?instalaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_gen.sh | 4 ++-- register.sh | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/data_gen.sh b/data_gen.sh index acf5728..e051db5 100755 --- a/data_gen.sh +++ b/data_gen.sh @@ -42,12 +42,12 @@ counter=$(cat $install_dir/counter) uuid="$(uuidgen)" timestamp="$(date +%s)" json="{\"transaction_uuid\":\"$uuid\",\"controller_id\":\"$name\",\"timestamp\":\"$timestamp\",\"error_code\":\"10\",\"coordinates\":{\"lat\":1,\"lng\":1},\"battery_status\":\"98\",\"sample\":\"0\",\"storage\":\"uso del almacenamiento\",\"arduinos\":[$sensores]}" - touch /opt/nodemecu/lock + touch $install_dir/lock file=$(date +%Y%m%d%H%M%S)-$(uuidgen) for ((i=1 ; i <=3 ; i++));do if echo $json | jsonlint-php 2> /dev/null;then echo $json > /opt/nodemecu/stack/$file && rm /opt/nodemecu/lock && echo $((counter+1)) > $install_dir/counter && break else - echo "$(date +%Y-%m-%d-%H:%M:%S) - No se pudo obtener información." >> /opt/nodemecu/errors.log && sleep 1 + echo "$(date +%Y-%m-%d-%H:%M:%S) - No se pudo obtener información." >> $install_dir/errors.log && sleep 1 fi done diff --git a/register.sh b/register.sh index 93dcdb6..f53986d 100755 --- a/register.sh +++ b/register.sh @@ -1,21 +1,21 @@ #!/bin/bash #set -e source /etc/nodemecu.conf -source /opt/nodemecu/functions +source $install_dir/functions # Revisando stack -for filename in /opt/nodemecu/stack/*;do - test "$filename" = "/opt/nodemecu/stack/\*" || break - jsonlint-php $filename > /dev/null || mv -v $filename $corrupt +for filename in $install_dir/stack/*;do + test "$filename" = "$install_dir/stack/\*" || break + jq $filename >/dev/null 2>&1 || mv -v $filename $corrupt done while :;do ping -c 1 fsf.org > /dev/null 2>&1 || continue test_url="$(curl -s -X POST -o /dev/null -w "%{http_code}" $url)" if [ $test_url -eq 404 ];then - echo "$(date +%Y-%m-%d-%H:%M:%S) - $url - $test_url" >> /opt/nodemecu/errors.log && sleep 300 && continue + echo "$(date +%Y-%m-%d-%H:%M:%S) - $url - $test_url" >> $install_dir/errors.log && sleep 300 && continue fi [ -f $install_dir/lock ] && continue file=$(get_stack) @@ -42,6 +42,6 @@ while :;do rm $curl_err fi -done +done exit -- 2.45.2 From c29f1dc07e0a0dbe388d25d349c0902de6bab7a0 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:16:39 -0300 Subject: [PATCH 02/21] crear el directorio de archivos corruptos --- install.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/install.sh b/install.sh index 81fdf8c..eb9ce2b 100755 --- a/install.sh +++ b/install.sh @@ -1,7 +1,7 @@ #!/bin/bash files="data_gen.sh monitor.sh register.sh uninstall.sh monitor.web bin functions counter" config=nodemecu.conf.sample -source $config +source $config echo -e "1. Instalando dependencias" @@ -10,18 +10,19 @@ sudo pip install pyserial echo "" -# Estructura de directorios -echo -e "2. Creando directorios y copiando archivos" +# Estructura de directorios +echo -e "2. Creando directorios y copiando archivos" sudo mkdir -vp $install_dir/archives/historical -sudo mkdir -vp $install_dir/archives/logs +sudo mkdir -vp $install_dir/archives/logs sudo mkdir $historical sudo mkdir $stack -echo "" -sudo cp -vr $files $install_dir +sudo mkdir $corrupt +echo "" +sudo cp -vr $files $install_dir sudo cp -v $config /etc/nodemecu.conf -sudo ln -s $install_dir/bin/nodemecu /usr/bin/nodemecu -sudo touch $log +sudo ln -s $install_dir/bin/nodemecu /usr/bin/nodemecu +sudo touch $log echo "" echo "3. Configurando systemd" -- 2.45.2 From 253992520bf391a84d6efc09bd8d93369887c9c3 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:17:10 -0300 Subject: [PATCH 03/21] no hace falta salir --- register.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/register.sh b/register.sh index f53986d..b83d9b0 100755 --- a/register.sh +++ b/register.sh @@ -1,6 +1,6 @@ #!/bin/bash #set -e -source /etc/nodemecu.conf +source nodemecu.conf source $install_dir/functions @@ -41,7 +41,4 @@ while :;do echo $err_time - $local_transaction_uuid - server status: $server_error $srv_msg $curl_msg >> $log rm $curl_err fi - done -exit - -- 2.45.2 From 3bd1b4cf48a0e835176709b44232cbb4dfc62a1f Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:18:32 -0300 Subject: [PATCH 04/21] cambia local --- register.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/register.sh b/register.sh index b83d9b0..e54e3f3 100755 --- a/register.sh +++ b/register.sh @@ -1,6 +1,6 @@ #!/bin/bash #set -e -source nodemecu.conf +source /etc/nodemecu.conf source $install_dir/functions -- 2.45.2 From 0f0a74312305aa56eb4ce77a0d70595f0500966b Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:25:16 -0300 Subject: [PATCH 05/21] =?UTF-8?q?no=20expandir=20directorios=20vac=C3=ADos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- register.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/register.sh b/register.sh index e54e3f3..f207c78 100755 --- a/register.sh +++ b/register.sh @@ -3,11 +3,12 @@ source /etc/nodemecu.conf source $install_dir/functions +# No expandir directorios vacíos +shopt -s nullglob # Revisando stack for filename in $install_dir/stack/*;do - test "$filename" = "$install_dir/stack/\*" || break jq $filename >/dev/null 2>&1 || mv -v $filename $corrupt done -- 2.45.2 From ee4dc72a0a5ed5958ea14d2c99bba79c9a732ec3 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:25:27 -0300 Subject: [PATCH 06/21] =?UTF-8?q?no=20hardcodear=20el=20directorio=20de=20?= =?UTF-8?q?instalaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 1f0f68e..b18011c 100644 --- a/functions +++ b/functions @@ -1,8 +1,8 @@ get_stack () { if [[ ! -z $1 && $1 == "wc" ]];then - ls /opt/nodemecu/stack | wc -l + ls $install_dir/stack | wc -l else - ls /opt/nodemecu/stack | tail -1 + ls $install_dir/stack | tail -1 fi } -- 2.45.2 From 8df59231a530cf96e27bd5d8e0e3eb71255b8456 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:28:11 -0300 Subject: [PATCH 07/21] poder configurar el linter de json --- data_gen.sh | 4 ++-- nodemecu.conf.sample | 1 + register.sh | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/data_gen.sh b/data_gen.sh index e051db5..a318bfa 100755 --- a/data_gen.sh +++ b/data_gen.sh @@ -45,8 +45,8 @@ json="{\"transaction_uuid\":\"$uuid\",\"controller_id\":\"$name\",\"timestamp\": touch $install_dir/lock file=$(date +%Y%m%d%H%M%S)-$(uuidgen) for ((i=1 ; i <=3 ; i++));do - if echo $json | jsonlint-php 2> /dev/null;then - echo $json > /opt/nodemecu/stack/$file && rm /opt/nodemecu/lock && echo $((counter+1)) > $install_dir/counter && break + if echo $json | $json_linter >/dev/null 2>&1 ;then + echo $json > $install_dir/stack/$file && rm $install_dir/lock && echo $((counter+1)) > $install_dir/counter && break else echo "$(date +%Y-%m-%d-%H:%M:%S) - No se pudo obtener información." >> $install_dir/errors.log && sleep 1 fi diff --git a/nodemecu.conf.sample b/nodemecu.conf.sample index bfb5883..aadd101 100644 --- a/nodemecu.conf.sample +++ b/nodemecu.conf.sample @@ -2,6 +2,7 @@ url=https://ectomobile.sutty.nl/transactions name= interval= mode=test +json_linter=jsonlint-php # AJUSTES GENERALES diff --git a/register.sh b/register.sh index f207c78..66c93e5 100755 --- a/register.sh +++ b/register.sh @@ -9,7 +9,7 @@ shopt -s nullglob # Revisando stack for filename in $install_dir/stack/*;do - jq $filename >/dev/null 2>&1 || mv -v $filename $corrupt + $json_linter $filename >/dev/null 2>&1 || mv -v $filename $corrupt done while :;do -- 2.45.2 From 303e35b07571fd86d94c003a8f25548c56c72f41 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:29:58 -0300 Subject: [PATCH 08/21] chequear si hay un lock primero --- register.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/register.sh b/register.sh index 66c93e5..4fbe58c 100755 --- a/register.sh +++ b/register.sh @@ -13,12 +13,13 @@ for filename in $install_dir/stack/*;do done while :;do + [ -f $install_dir/lock ] && continue + ping -c 1 fsf.org > /dev/null 2>&1 || continue test_url="$(curl -s -X POST -o /dev/null -w "%{http_code}" $url)" if [ $test_url -eq 404 ];then echo "$(date +%Y-%m-%d-%H:%M:%S) - $url - $test_url" >> $install_dir/errors.log && sleep 300 && continue fi - [ -f $install_dir/lock ] && continue file=$(get_stack) [ -z $file ] && continue local_transaction_uuid=$(jq -r '."transaction_uuid"' $stack/$file) -- 2.45.2 From 46541ea34d18df008c3bf9c2a7aec85be58b6fd3 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:31:55 -0300 Subject: [PATCH 09/21] fracciones gringas --- register.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/register.sh b/register.sh index 4fbe58c..3c7ac00 100755 --- a/register.sh +++ b/register.sh @@ -23,7 +23,7 @@ while :;do file=$(get_stack) [ -z $file ] && continue local_transaction_uuid=$(jq -r '."transaction_uuid"' $stack/$file) - remote_transaction=$(curl -s --connect-timeout 0,9 --show-error -w "~%{http_code}" -X POST -H "Content-Type: application/json" -d @$stack/$file $url 2> $curl_err) + remote_transaction=$(curl -s --connect-timeout 0.9 --show-error -w "~%{http_code}" -X POST -H "Content-Type: application/json" -d @$stack/$file $url 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 -- 2.45.2 From 676b3628bb6a3a5ff39a9de8e8e9ab345d954055 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:33:24 -0300 Subject: [PATCH 10/21] usar el log configurado --- data_gen.sh | 2 +- register.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data_gen.sh b/data_gen.sh index a318bfa..fbb3c62 100755 --- a/data_gen.sh +++ b/data_gen.sh @@ -48,6 +48,6 @@ json="{\"transaction_uuid\":\"$uuid\",\"controller_id\":\"$name\",\"timestamp\": if echo $json | $json_linter >/dev/null 2>&1 ;then echo $json > $install_dir/stack/$file && rm $install_dir/lock && echo $((counter+1)) > $install_dir/counter && break else - echo "$(date +%Y-%m-%d-%H:%M:%S) - No se pudo obtener información." >> $install_dir/errors.log && sleep 1 + echo "$(date +%Y-%m-%d-%H:%M:%S) - No se pudo obtener información." >> $log && sleep 1 fi done diff --git a/register.sh b/register.sh index 3c7ac00..d7d680a 100755 --- a/register.sh +++ b/register.sh @@ -18,7 +18,7 @@ while :;do ping -c 1 fsf.org > /dev/null 2>&1 || continue test_url="$(curl -s -X POST -o /dev/null -w "%{http_code}" $url)" if [ $test_url -eq 404 ];then - echo "$(date +%Y-%m-%d-%H:%M:%S) - $url - $test_url" >> $install_dir/errors.log && sleep 300 && continue + echo "$(date +%Y-%m-%d-%H:%M:%S) - $url - $test_url" >> $log && sleep 300 && continue fi file=$(get_stack) [ -z $file ] && continue -- 2.45.2 From a921e1fd5d76c238f9c522073179a6177d8108e5 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:35:39 -0300 Subject: [PATCH 11/21] usar el archivo de error configurado MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit además no hace falta borrarlo --- register.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/register.sh b/register.sh index d7d680a..02cdc0b 100755 --- a/register.sh +++ b/register.sh @@ -39,8 +39,7 @@ while :;do 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 -- 2.45.2 From f148b14b92fd98945b0295eaab08a1e02d30d50f Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:37:09 -0300 Subject: [PATCH 12/21] no declarar variables que se usan una vez --- register.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/register.sh b/register.sh index 02cdc0b..3f87505 100755 --- a/register.sh +++ b/register.sh @@ -37,9 +37,8 @@ while :;do # 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="- $(<$curl_err)" - echo $err_time - $local_transaction_uuid - server status: $server_error $srv_msg $curl_msg >> $log + echo $(date +%Y-%m-%d-%H:%M:%S) - $local_transaction_uuid - server status: $server_error $srv_msg $curl_msg >> $log fi done -- 2.45.2 From 0b77d81c2b702b7c521b88f8cb33810145aeb4c3 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:47:52 -0300 Subject: [PATCH 13/21] detener el loop si se lo pedimos amablemente --- register.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/register.sh b/register.sh index 3f87505..75858e8 100755 --- a/register.sh +++ b/register.sh @@ -13,6 +13,7 @@ for filename in $install_dir/stack/*;do done while :;do + [ -f $install_dir/stop ] && break [ -f $install_dir/lock ] && continue ping -c 1 fsf.org > /dev/null 2>&1 || continue -- 2.45.2 From 623dccb301073038cfaf4c901d84120503f0d416 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:49:39 -0300 Subject: [PATCH 14/21] =?UTF-8?q?solo=20el=20estado=20200=20indica=20que?= =?UTF-8?q?=20est=C3=A1=20todo=20bien?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- register.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/register.sh b/register.sh index 75858e8..7484680 100755 --- a/register.sh +++ b/register.sh @@ -18,7 +18,7 @@ while :;do ping -c 1 fsf.org > /dev/null 2>&1 || continue test_url="$(curl -s -X POST -o /dev/null -w "%{http_code}" $url)" - if [ $test_url -eq 404 ];then + if [ $test_url -ne 200 ];then echo "$(date +%Y-%m-%d-%H:%M:%S) - $url - $test_url" >> $log && sleep 300 && continue fi file=$(get_stack) -- 2.45.2 From 6105e5948e6e9491513cddc00c4edefc084db530 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 14:53:01 -0300 Subject: [PATCH 15/21] el id de transaccion es el mismo del archivo --- data_gen.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_gen.sh b/data_gen.sh index fbb3c62..b0d53cf 100755 --- a/data_gen.sh +++ b/data_gen.sh @@ -43,7 +43,7 @@ uuid="$(uuidgen)" timestamp="$(date +%s)" json="{\"transaction_uuid\":\"$uuid\",\"controller_id\":\"$name\",\"timestamp\":\"$timestamp\",\"error_code\":\"10\",\"coordinates\":{\"lat\":1,\"lng\":1},\"battery_status\":\"98\",\"sample\":\"0\",\"storage\":\"uso del almacenamiento\",\"arduinos\":[$sensores]}" touch $install_dir/lock - file=$(date +%Y%m%d%H%M%S)-$(uuidgen) + file=$(date +%Y%m%d%H%M%S)-$uuid for ((i=1 ; i <=3 ; i++));do if echo $json | $json_linter >/dev/null 2>&1 ;then echo $json > $install_dir/stack/$file && rm $install_dir/lock && echo $((counter+1)) > $install_dir/counter && break -- 2.45.2 From 4411d7ee0c72c44069a00c0c30439a6efa29b623 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 15:06:00 -0300 Subject: [PATCH 16/21] =?UTF-8?q?probar=20la=20conexi=C3=B3n=20s=C3=B3lo?= =?UTF-8?q?=20cuando=20hay=20un=20archivo=20para=20enviar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- register.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/register.sh b/register.sh index 7484680..444d65a 100755 --- a/register.sh +++ b/register.sh @@ -16,15 +16,14 @@ while :;do [ -f $install_dir/stop ] && break [ -f $install_dir/lock ] && continue + file=$(get_stack) + [ -z $file ] && continue + ping -c 1 fsf.org > /dev/null 2>&1 || continue test_url="$(curl -s -X POST -o /dev/null -w "%{http_code}" $url)" if [ $test_url -ne 200 ];then echo "$(date +%Y-%m-%d-%H:%M:%S) - $url - $test_url" >> $log && sleep 300 && continue fi - file=$(get_stack) - [ -z $file ] && continue - local_transaction_uuid=$(jq -r '."transaction_uuid"' $stack/$file) - remote_transaction=$(curl -s --connect-timeout 0.9 --show-error -w "~%{http_code}" -X POST -H "Content-Type: application/json" -d @$stack/$file $url 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 -- 2.45.2 From 2feee6f70b40c2f543746f49f7114fcf888d66c4 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 15:07:45 -0300 Subject: [PATCH 17/21] mover los archivos fallados a otro directorio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit de lo contrario detienen el envío porque el stack siempre devuelve el fallado --- install.sh | 1 + nodemecu.conf.sample | 1 + register.sh | 13 ++++++++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index eb9ce2b..a477195 100755 --- a/install.sh +++ b/install.sh @@ -18,6 +18,7 @@ sudo mkdir -vp $install_dir/archives/logs sudo mkdir $historical sudo mkdir $stack sudo mkdir $corrupt +sudo mkdir $failed echo "" sudo cp -vr $files $install_dir sudo cp -v $config /etc/nodemecu.conf diff --git a/nodemecu.conf.sample b/nodemecu.conf.sample index aadd101..4d1c3d0 100644 --- a/nodemecu.conf.sample +++ b/nodemecu.conf.sample @@ -15,3 +15,4 @@ stack=$install_dir/stack historical=$install_dir/historical log=$install_dir/errors.log corrupt=$install_dir/corrupt +failed=$install_dir/failed diff --git a/register.sh b/register.sh index 444d65a..b15064f 100755 --- a/register.sh +++ b/register.sh @@ -24,15 +24,18 @@ while :;do if [ $test_url -ne 200 ];then echo "$(date +%Y-%m-%d-%H:%M:%S) - $url - $test_url" >> $log && sleep 300 && continue fi + + file="$stack/$file" + local_transaction_uuid="$(echo "$file" | cut -d - -f 2-)" + remote_transaction=$(curl -s --connect-timeout 1 --show-error -w "~%{http_code}" -X POST -H "Content-Type: application/json" -d @$file $url 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 $stack/$file $historical - echo -e "$remote_response: \e[92mOK\e[0m" - fi + if [ "$local_transaction_uuid" = "$remote_response" ]; then + mv $file $historical + echo -e "$remote_response: \e[92mOK\e[0m" else + mv $file $failed echo -e "$local_transaction_uuid: \e[91mFAIL\e[0m" # errores unset srv_msg -- 2.45.2 From b8d45a0adfc957dfa7b15ed9b0548c49007fbf01 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 15:09:06 -0300 Subject: [PATCH 18/21] no crear los directorios si ya existen --- install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index a477195..e101c23 100755 --- a/install.sh +++ b/install.sh @@ -15,10 +15,10 @@ echo -e "2. Creando directorios y copiando archivos" sudo mkdir -vp $install_dir/archives/historical sudo mkdir -vp $install_dir/archives/logs -sudo mkdir $historical -sudo mkdir $stack -sudo mkdir $corrupt -sudo mkdir $failed +sudo mkdir -vp $historical +sudo mkdir -vp $stack +sudo mkdir -vp $corrupt +sudo mkdir -vp $failed echo "" sudo cp -vr $files $install_dir sudo cp -v $config /etc/nodemecu.conf -- 2.45.2 From 9fef227f5eb763f8a362196937611c26e729b011 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 15:09:52 -0300 Subject: [PATCH 19/21] =?UTF-8?q?get=5Fstack=20solo=20trae=20el=20=C3=BAlt?= =?UTF-8?q?imo=20archivo=20de=20la=20cola?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit las funciones hacen una sola cosa --- functions | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/functions b/functions index b18011c..28ae239 100644 --- a/functions +++ b/functions @@ -1,10 +1,3 @@ get_stack () { - if [[ ! -z $1 && $1 == "wc" ]];then - ls $install_dir/stack | wc -l - else - ls $install_dir/stack | tail -1 - fi + ls $install_dir/stack | tail -1 } - - - -- 2.45.2 From d2f30d8fe78a6f3d7d44a65b8edaa332f29bf332 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 15:13:39 -0300 Subject: [PATCH 20/21] =?UTF-8?q?si=20no=20hay=20archivos=20que=20enviar?= =?UTF-8?q?=20esperar=20al=20pr=C3=B3ximo=20intervalo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- register.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/register.sh b/register.sh index b15064f..06f4c7e 100755 --- a/register.sh +++ b/register.sh @@ -17,7 +17,7 @@ while :;do [ -f $install_dir/lock ] && continue file=$(get_stack) - [ -z $file ] && continue + [ -z $file ] && sleep ${interval:-1}m && continue ping -c 1 fsf.org > /dev/null 2>&1 || continue test_url="$(curl -s -X POST -o /dev/null -w "%{http_code}" $url)" -- 2.45.2 From d1e44141f6788af944923ea4028073b2348a29e8 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 3 Mar 2022 16:09:31 -0300 Subject: [PATCH 21/21] usar tabs --- register.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/register.sh b/register.sh index 06f4c7e..506b89d 100755 --- a/register.sh +++ b/register.sh @@ -25,23 +25,23 @@ while :;do echo "$(date +%Y-%m-%d-%H:%M:%S) - $url - $test_url" >> $log && sleep 300 && continue fi - file="$stack/$file" + file="$stack/$file" local_transaction_uuid="$(echo "$file" | cut -d - -f 2-)" remote_transaction=$(curl -s --connect-timeout 1 --show-error -w "~%{http_code}" -X POST -H "Content-Type: application/json" -d @$file $url 2> $curl_err) remote_response="$(echo $remote_transaction | cut -d '~' -f 1)" server_error="$(echo $remote_transaction | cut -d '~' -f 2)" - if [ "$local_transaction_uuid" = "$remote_response" ]; then - mv $file $historical - echo -e "$remote_response: \e[92mOK\e[0m" + if [ "$local_transaction_uuid" = "$remote_response" ]; then + mv $file $historical + echo -e "$remote_response: \e[92mOK\e[0m" else - mv $file $failed + mv $file $failed echo -e "$local_transaction_uuid: \e[91mFAIL\e[0m" # errores unset srv_msg unset curl_msg [ ! -z "$remote_response" ] && srv_msg="- $( echo $remote_response | grep -o '.*')" [ -s "$curl_err" ] && curl_msg="- $(<$curl_err)" - echo $(date +%Y-%m-%d-%H:%M:%S) - $local_transaction_uuid - server status: $server_error $srv_msg $curl_msg >> $log + echo $(date +%Y-%m-%d-%H:%M:%S) - $local_transaction_uuid - server status: $server_error $srv_msg $curl_msg >> $log fi done -- 2.45.2