Skip to content

Commit 2b1f5cc

Browse files
committed
Fix
- Fix new return code for empty JSON in JQ > 1.6 - Fix the error on oci_csv_usage.sh after FOCUS files were introduced with spaces on their names
1 parent 6f1f899 commit 2b1f5cc

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

oci_csv_usage.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#************************************************************************
2222
# Available at: https://github.com/dbarj/oci-scripts
2323
# Created on: May/2020 by Rodrigo Jorge
24-
# Version 1.04
24+
# Version 1.05
2525
#************************************************************************
2626
set -eo pipefail
2727

@@ -285,37 +285,39 @@ function csvUsageReport ()
285285
return $v_ret
286286
fi
287287

288+
OIFS="$IFS"; IFS=$'\n'
288289
for v_item in $l_itens
289290
do
291+
IFS="$OIFS"
290292
c_name=$(cut -d ',' -f 1 <<< "$v_item" | sed 's/^.//; s/.$//')
291293
c_fdate=$(cut -d ',' -f 2 <<< "$v_item" | sed 's/^.//; s/.$//')
292294
c_fdate_YMD=${c_fdate:0:10}
293295
c_fdate_hms=${c_fdate:11:8}
294296
c_fdate_epoch=$(ConvYMDToEpoch ${c_fdate_YMD} ${c_fdate_hms})
295297
if [ $c_fdate_epoch -lt $v_start_epoch -o $c_fdate_epoch -gt $v_end_epoch ]
296298
then
297-
echoDebug "${c_name} date is ${c_fdate} - Outside requested scope." 2
299+
echoDebug "'${c_name}' date is ${c_fdate} - Outside requested scope." 2
298300
continue
299301
fi
300302
c_file=$(sed 's/\//_/g' <<< "${c_name}")
301303
if ${v_execute}
302304
then
303-
echo "- Getting ${c_name} created on ${c_fdate}."
305+
echo "- Getting '${c_name}' created on ${c_fdate}."
304306
v_search="${c_file}_${c_fdate}"
305307
# Will first try to get the output from the historical zip. If can't find it, will call the get function.
306308
getFileFromZip "${v_search}" "${c_file}" && v_ret=$? || v_ret=$?
307309
if [ $v_ret -ne 0 ]
308310
then
309311
# Run
310-
v_oci_usagereport="os object get --namespace bling --bucket-name ${v_tenancy_id} --name $c_name --file ${c_file}"
312+
v_oci_usagereport="os object get --namespace bling --bucket-name ${v_tenancy_id} --name '$c_name' --file '${c_file}'"
311313
v_out=$(jsonSimple "${v_oci_usagereport}" ".")
312314
(putFileOnZip "${v_search}" "${c_file}") || true
313315
else
314-
echoDebug "Got \"${c_file}\" from Zip Hist."
316+
echoDebug "Got '${c_file}' from Zip Hist."
315317
fi
316318
${v_zip} -qm "$v_outfile" "${c_file}"
317319
else
318-
echo "${v_oci} os object get --namespace bling --bucket-name ${v_tenancy_id} --name $c_name --file ${c_file}"
320+
echo "${v_oci} os object get --namespace bling --bucket-name ${v_tenancy_id} --name '$c_name' --file '${c_file}'"
319321
fi
320322
done
321323

@@ -387,7 +389,13 @@ function runOCI ()
387389
else
388390
return $b_ret
389391
fi
390-
${v_jq} -e . >/dev/null 2>&1 <<< "${v_out}" && v_ret=$? || v_ret=$?
392+
# JQ <= 1.6 returns 0 on empty strings. JQ > 1.6 returns 4.
393+
if [ -n "${v_out}" ]
394+
then
395+
${v_jq} -e . >/dev/null 2>&1 <<< "${v_out}" && v_ret=$? || v_ret=$?
396+
else
397+
v_ret=0
398+
fi
391399
echo "${v_out}"
392400
return ${v_ret}
393401
}
@@ -512,7 +520,7 @@ function putFileOnZip ()
512520
else
513521
[ $(wc -l <<< "${v_line}") -gt 1 ] && return 1
514522
fi
515-
echoDebug "Adding ${v_file} to ${HIST_ZIP_FILE}." 2
523+
echoDebug "Adding '${v_file}' to ${HIST_ZIP_FILE}." 2
516524
${v_zip} -qj ${HIST_ZIP_FILE} "${v_list}"
517525
${v_zip} -qj ${HIST_ZIP_FILE} "${v_file}"
518526
return 0

oci_json_audit.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#************************************************************************
2222
# Available at: https://github.com/dbarj/oci-scripts
2323
# Created on: Aug/2019 by Rodrigo Jorge
24-
# Version 1.10
24+
# Version 1.11
2525
#************************************************************************
2626
set -eo pipefail
2727

@@ -557,7 +557,13 @@ function runOCI ()
557557
else
558558
echoDebug "Got \"${v_search}\" from Zip Hist."
559559
fi
560-
${v_jq} -e . >/dev/null 2>&1 <<< "${v_out}" && v_ret=$? || v_ret=$?
560+
# JQ <= 1.6 returns 0 on empty strings. JQ > 1.6 returns 4.
561+
if [ -n "${v_out}" ]
562+
then
563+
${v_jq} -e . >/dev/null 2>&1 <<< "${v_out}" && v_ret=$? || v_ret=$?
564+
else
565+
v_ret=0
566+
fi
561567
echo "${v_out}"
562568
return ${v_ret}
563569
}

oci_json_billing.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#************************************************************************
2222
# Available at: https://github.com/dbarj/oci-scripts
2323
# Created on: May/2019 by Rodrigo Jorge
24-
# Version 1.10
24+
# Version 1.11
2525
#************************************************************************
2626
set -eo pipefail
2727

@@ -404,7 +404,13 @@ function runCurl ()
404404
else
405405
echoDebug "Got \"${v_arg1}\" from Zip Hist."
406406
fi
407-
${v_jq} -e . >/dev/null 2>&1 <<< "${v_out}" && v_ret=$? || v_ret=$?
407+
# JQ <= 1.6 returns 0 on empty strings. JQ > 1.6 returns 4.
408+
if [ -n "${v_out}" ]
409+
then
410+
${v_jq} -e . >/dev/null 2>&1 <<< "${v_out}" && v_ret=$? || v_ret=$?
411+
else
412+
v_ret=0
413+
fi
408414
echo "${v_out}"
409415
return ${v_ret}
410416
}

oci_json_monitoring.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#************************************************************************
2222
# Available at: https://github.com/dbarj/oci-scripts
2323
# Created on: Aug/2019 by Rodrigo Jorge
24-
# Version 1.04
24+
# Version 1.05
2525
#************************************************************************
2626
set -eo pipefail
2727

@@ -666,7 +666,13 @@ function runOCI ()
666666
else
667667
echoDebug "Got \"${v_search}\" from Zip Hist."
668668
fi
669-
${v_jq} -e . >/dev/null 2>&1 <<< "${v_out}" && v_ret=$? || v_ret=$?
669+
# JQ <= 1.6 returns 0 on empty strings. JQ > 1.6 returns 4.
670+
if [ -n "${v_out}" ]
671+
then
672+
${v_jq} -e . >/dev/null 2>&1 <<< "${v_out}" && v_ret=$? || v_ret=$?
673+
else
674+
v_ret=0
675+
fi
670676
echo "${v_out}"
671677
return ${v_ret}
672678
}

0 commit comments

Comments
 (0)