From c9f5be3a7db472f9b31ba044dabaff8051105e26 Mon Sep 17 00:00:00 2001 From: Ying Xie Date: Tue, 28 Sep 2021 16:00:18 -0700 Subject: [PATCH] [show techsupport] fix bash errors in generate_dump script (#1844) What I did Fix: Azure/sonic-buildimage#8850 Issue was introduced by #1723, #1833, and #1843 (pending merge) The error_handler is a great idea but the bash script needs to be error free first. How I did it Fix bash script errors. How to verify it run show techsupport test.. Signed-off-by: Ying Xie --- scripts/generate_dump | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/scripts/generate_dump b/scripts/generate_dump index 7096c7c04a..6e2ab6728c 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -193,8 +193,9 @@ save_cmd() { if $NOOP; then echo "${timeout_cmd} $cmd $redirect '$filepath'" else - eval "${timeout_cmd} $cmd" "$redirect" "$filepath" - if [ $? -ne 0 ]; then + RC=0 + eval "${timeout_cmd} $cmd" "$redirect" "$filepath" || RC=$? + if [ $RC -ne 0 ]; then echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes." fi fi @@ -983,26 +984,30 @@ save_warmboot_files() { save_crash_files() { # archive core dump files trap 'handle_error $? $LINENO' ERR - for file in $(find_files "/var/core/"); do - # don't gzip already-gzipped log files :) - if [ -z "${file##*.gz}" ]; then - save_file $file core false - else - save_file $file core true - fi - done + if [ -d /var/core/ ]; then + for file in $(find_files "/var/core/"); do + # don't gzip already-gzipped log files :) + if [ -z "${file##*.gz}" ]; then + save_file $file core false + else + save_file $file core true + fi + done + fi # archive kernel dump files - [ -d /var/crash/ ] && for file in $(find_files "/var/crash/"); do - # don't gzip already-gzipped dmesg files :) - if [ ! ${file} = "/var/crash/kexec_cmd" -a ! ${file} = "/var/crash/export" ]; then - if [[ ${file} == *"kdump."* ]]; then - save_file $file kdump false - else - save_file $file kdump true + if [ -d /var/crash/ ]; then + for file in $(find_files "/var/crash/"); do + # don't gzip already-gzipped dmesg files :) + if [ ! ${file} = "/var/crash/kexec_cmd" -a ! ${file} = "/var/crash/export" ]; then + if [[ ${file} == *"kdump."* ]]; then + save_file $file kdump false + else + save_file $file kdump true + fi fi - fi - done + done + fi } ###############################################################################