mardi 18 septembre 2018

Count IF process , what is wrong?

i m learning bash I need to count the proces on an IF and on ELSE. But in the END of Program this show me alway ZERO. But if i put the echo in if show correctly. What i going wrong ? Thx

My Code

# CHEQUEA SI  EXISTE JSON2.ML - SI NO EXISTE REALIZA EL POST
acount=0
acounte=0
bcount=0
bcounte=0
api=APP_USR-1447105125686073-091812-eeceb6a719ab67de157c32d7c0d6dbc7-335445253




# Borra archivos con errores  
find -type f -name '*.ml' -size 0 | while read f; do rm "${f%.*}."* ; done
find -type f -name '*.ml' -exec grep -c -q '"Validation error","error"' '{}' \; -exec rm '{}' \;
find -type f -name '*.ml' -exec grep -c -q 'invalid_token' '{}' \; -exec rm '{}' \;
find -type f -name '*.ml' -exec grep -c -q 'access_token.invalid' '{}' \; -exec rm '{}' \;
find -type f -name '*.ml' -exec grep -c -q 'body.invalid_field_types' '{}' \; -exec rm '{}' \;
find -type f -name '*.ml' -exec grep -c -q 'item.price.invalid' '{}' \; -exec rm '{}' \;
find -type f -name '*.ml' -exec grep -c -q 'FURY_SAVE_KVSAPI_ERROR' '{}' \; -exec rm '{}' \;


# Busca archivos .ml si no encuentra sube articulo JSON2
find . -type f -name '*.json2' | xargs bash -c 'for fname
do if [ ! -e ${fname}.ml ]
then curl -X POST -H "Content-Type: application/json" -d @${fname} https://web/api > ${fname}.ml 
(( acount++ ))
echo $acount
else
(( acounte++ ))
fi

done

' bash

# Busca archivos .ml si no encuentra sube articulo JSON3
find . -type f -name '*.json3' | xargs bash -c 'for fname
do if [ ! -e ${fname}.ml ]
then curl -X POST -H "Content-Type: application/json" -d @${fname} https://web/api > ${fname}.ml  
(( bcount++ ))
echo $bcount
else
(( bcounte++ ))
fi


done
echo  Total archivos JSON2 no subidos $acounte
echo  Total archivos JSON2 subidos $acount
echo  Total archivos JSON3 no subidos $bcounte
echo  Total archivos JSON3 subidos $bcount
tacounte=$(echo $acounte)
tacount=$(echo $acount)
tbcounte=$(echo $bcounte)
tbcount=$(echo $bcount)
' bash

echo  Total archivos JSON2 no subidos $tacounte
echo  Total archivos JSON2 subidos $tacount
echo  Total archivos JSON3 no subidos $tbcounte
echo  Total archivos JSON3 subidos $tbcount

This show

echo Total archivos JSON2 no subidos $tacounte 0

echo Total archivos JSON2 subidos $tacount 0

echo Total archivos JSON3 no subidos $tbcounte 0

echo Total archivos JSON3 subidos $tbcount 0

Aucun commentaire:

Enregistrer un commentaire