|
21 | 21 | #************************************************************************
|
22 | 22 | # Available at: https://github.com/dbarj/oci-scripts
|
23 | 23 | # Created on: May/2020 by Rodrigo Jorge
|
24 |
| -# Version 1.04 |
| 24 | +# Version 1.05 |
25 | 25 | #************************************************************************
|
26 | 26 | set -eo pipefail
|
27 | 27 |
|
@@ -285,37 +285,39 @@ function csvUsageReport ()
|
285 | 285 | return $v_ret
|
286 | 286 | fi
|
287 | 287 |
|
| 288 | + OIFS="$IFS"; IFS=$'\n' |
288 | 289 | for v_item in $l_itens
|
289 | 290 | do
|
| 291 | + IFS="$OIFS" |
290 | 292 | c_name=$(cut -d ',' -f 1 <<< "$v_item" | sed 's/^.//; s/.$//')
|
291 | 293 | c_fdate=$(cut -d ',' -f 2 <<< "$v_item" | sed 's/^.//; s/.$//')
|
292 | 294 | c_fdate_YMD=${c_fdate:0:10}
|
293 | 295 | c_fdate_hms=${c_fdate:11:8}
|
294 | 296 | c_fdate_epoch=$(ConvYMDToEpoch ${c_fdate_YMD} ${c_fdate_hms})
|
295 | 297 | if [ $c_fdate_epoch -lt $v_start_epoch -o $c_fdate_epoch -gt $v_end_epoch ]
|
296 | 298 | 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 |
298 | 300 | continue
|
299 | 301 | fi
|
300 | 302 | c_file=$(sed 's/\//_/g' <<< "${c_name}")
|
301 | 303 | if ${v_execute}
|
302 | 304 | then
|
303 |
| - echo "- Getting ${c_name} created on ${c_fdate}." |
| 305 | + echo "- Getting '${c_name}' created on ${c_fdate}." |
304 | 306 | v_search="${c_file}_${c_fdate}"
|
305 | 307 | # Will first try to get the output from the historical zip. If can't find it, will call the get function.
|
306 | 308 | getFileFromZip "${v_search}" "${c_file}" && v_ret=$? || v_ret=$?
|
307 | 309 | if [ $v_ret -ne 0 ]
|
308 | 310 | then
|
309 | 311 | # 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}'" |
311 | 313 | v_out=$(jsonSimple "${v_oci_usagereport}" ".")
|
312 | 314 | (putFileOnZip "${v_search}" "${c_file}") || true
|
313 | 315 | else
|
314 |
| - echoDebug "Got \"${c_file}\" from Zip Hist." |
| 316 | + echoDebug "Got '${c_file}' from Zip Hist." |
315 | 317 | fi
|
316 | 318 | ${v_zip} -qm "$v_outfile" "${c_file}"
|
317 | 319 | 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}'" |
319 | 321 | fi
|
320 | 322 | done
|
321 | 323 |
|
@@ -387,7 +389,13 @@ function runOCI ()
|
387 | 389 | else
|
388 | 390 | return $b_ret
|
389 | 391 | 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 |
391 | 399 | echo "${v_out}"
|
392 | 400 | return ${v_ret}
|
393 | 401 | }
|
@@ -512,7 +520,7 @@ function putFileOnZip ()
|
512 | 520 | else
|
513 | 521 | [ $(wc -l <<< "${v_line}") -gt 1 ] && return 1
|
514 | 522 | fi
|
515 |
| - echoDebug "Adding ${v_file} to ${HIST_ZIP_FILE}." 2 |
| 523 | + echoDebug "Adding '${v_file}' to ${HIST_ZIP_FILE}." 2 |
516 | 524 | ${v_zip} -qj ${HIST_ZIP_FILE} "${v_list}"
|
517 | 525 | ${v_zip} -qj ${HIST_ZIP_FILE} "${v_file}"
|
518 | 526 | return 0
|
|
0 commit comments