Skip to content

Commit b2da129

Browse files
authored
[show tech] fix more bash script format (sonic-net#1846)
What I did These format are not wrong. But if error_handler for $? is installed, these places would cause fase positives. How I did it Update more bash syntax to avoid false positives How to verify it Run show tech support test before merge. Signed-off-by: Ying Xie [email protected]
1 parent 280dd29 commit b2da129

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

scripts/generate_dump

+25-15
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ save_bcmcmd() {
6868
local do_gzip=${3:-false}
6969
local tarpath="${BASE}/dump/$filename"
7070
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
71-
[ ! -d $LOGDIR ] && $MKDIR $V -p $LOGDIR
71+
if [ ! -d $LOGDIR ]; then
72+
$MKDIR $V -p $LOGDIR
73+
fi
7274

7375
if [ $SKIP_BCMCMD -eq 1 ]; then
7476
echo "Skip $cmd"
@@ -81,14 +83,15 @@ save_bcmcmd() {
8183
if $NOOP; then
8284
echo "${timeout_cmd} $cmd &> '${filepath}'"
8385
else
84-
eval "${timeout_cmd} $cmd" &> "${filepath}"
85-
ret=$?
86+
ret=0
87+
eval "${timeout_cmd} $cmd" &> "${filepath}" || ret=$?
8688
if [ $ret -ne 0 ]; then
8789
if [ $ret -eq 124 ]; then
8890
echo "Command: $cmd timedout after ${TIMEOUT_MIN} minutes."
8991
else
90-
grep "polling socket timeout: Success" ${filepath} &>/dev/null
91-
if [ $? -eq 0 ]; then
92+
RC=0
93+
grep "polling socket timeout: Success" ${filepath} &>/dev/null || RC=$?
94+
if [ $RC -eq 0 ]; then
9295
echo "bcmcmd command timeout. Setting SKIP_BCMCMD to true ..."
9396
SKIP_BCMCMD=1
9497
fi
@@ -167,7 +170,9 @@ save_cmd() {
167170
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
168171
local redirect='&>'
169172
local redirect_eval='2>&1'
170-
[ ! -d $LOGDIR ] && $MKDIR $V -p $LOGDIR
173+
if [ ! -d $LOGDIR ]; then
174+
$MKDIR $V -p $LOGDIR
175+
fi
171176

172177
if ! $SAVE_STDERR
173178
then
@@ -186,8 +191,9 @@ save_cmd() {
186191
if $NOOP; then
187192
echo "${timeout_cmd} bash -c \"${cmds}\""
188193
else
189-
eval "${timeout_cmd} bash -c \"${cmds}\""
190-
if [ $? -ne 0 ]; then
194+
RC=0
195+
eval "${timeout_cmd} bash -c \"${cmds}\"" || RC=$?
196+
if [ $RC -ne 0 ]; then
191197
echo "Command: $cmds timedout after ${TIMEOUT_MIN} minutes."
192198
fi
193199
fi
@@ -266,12 +272,13 @@ copy_from_docker() {
266272
echo "${timeout_cmd} ${touch_cmd}"
267273
echo "${timeout_cmd} ${cp_cmd}"
268274
else
269-
eval "${timeout_cmd} ${touch_cmd}"
270-
if [ $? -ne 0 ]; then
275+
RC=0
276+
eval "${timeout_cmd} ${touch_cmd}" || RC=$?
277+
if [ $RC -ne 0 ]; then
271278
echo "Command: $touch_cmd timedout after ${TIMEOUT_MIN} minutes."
272279
fi
273-
eval "${timeout_cmd} ${cp_cmd}"
274-
if [ $? -ne 0 ]; then
280+
eval "${timeout_cmd} ${cp_cmd}" || RC=$?
281+
if [ $RC -ne 0 ]; then
275282
echo "Command: $cp_cmd timedout after ${TIMEOUT_MIN} minutes."
276283
fi
277284
fi
@@ -712,7 +719,9 @@ save_file() {
712719
local tar_path="${BASE}/$supp_dir/$(basename $orig_path)"
713720
local do_gzip=${3:-true}
714721
local do_tar_append=${4:-true}
715-
[ ! -d "$TARDIR/$supp_dir" ] && $MKDIR $V -p "$TARDIR/$supp_dir"
722+
if [ ! -d "$TARDIR/$supp_dir" ]; then
723+
$MKDIR $V -p "$TARDIR/$supp_dir"
724+
fi
716725

717726
if $do_gzip; then
718727
gz_path="${gz_path}.gz"
@@ -1288,8 +1297,9 @@ main() {
12881297
$RM $V -rf $TARDIR
12891298

12901299
if $DO_COMPRESS; then
1291-
$GZIP $V $TARFILE
1292-
if [ $? -eq 0 ]; then
1300+
RC=0
1301+
$GZIP $V $TARFILE || RC=$?
1302+
if [ $RC -eq 0 ]; then
12931303
TARFILE="${TARFILE}.gz"
12941304
else
12951305
echo "WARNING: gzip operation appears to have failed." >&2

0 commit comments

Comments
 (0)