Fix the exit code return issue in shell scripts#1107
Merged
liat-grozovik merged 2 commits intosonic-net:masterfrom Sep 16, 2019
wangxin:capture-shell-err
Merged
Fix the exit code return issue in shell scripts#1107liat-grozovik merged 2 commits intosonic-net:masterfrom wangxin:capture-shell-err
liat-grozovik merged 2 commits intosonic-net:masterfrom
wangxin:capture-shell-err
Conversation
In shell script, by default exit code of the last command in commands connected by pipe is returned. If previous command returned none zero exit code, the error is not captured. If ansible run such script in playbook, the script issue is ignored and ansible is not aware of it. The fix is to add "set -o pipefail" in shell scripts. And put the commands embedded in for loop statement to a separate statement. Signed-off-by: Xin Wang <xinw@mellanox.com>
keboliu
reviewed
Sep 11, 2019
keboliu
approved these changes
Sep 11, 2019
liat-grozovik
approved these changes
Sep 16, 2019
Collaborator
|
@wangxin can you create a separate PR for 201811 branch or advise dependencies to be picked? This PR doesn't cherry-pick cleanly. |
1 task
Collaborator
Author
Collaborator
kazinator-arista
pushed a commit
to kazinator-arista/sonic-mgmt
that referenced
this pull request
Mar 4, 2026
…omatically (#24670) #### Why I did it src/sonic-swss-common ``` * 36f40a1 - (HEAD -> 202405, origin/202405) Automated agent pool migration for branch 202405 (sonic-net#1107) (21 hours ago) [yijingyan2] ``` #### How I did it #### How to verify it #### Description for the changelog
kazinator-arista
pushed a commit
to kazinator-arista/sonic-mgmt
that referenced
this pull request
Mar 4, 2026
Revert "Revert " [201911]show interface counters for multi ASIC devices (sonic-net#1104)"" Revert "Revert "Pfcstat (sonic-net#1097)"" [show] Fix 'show int neighbor expected' (sonic-net#1106) Update argument for docker exec it->i (sonic-net#1118) Update to make config load/reload backward compatible. (sonic-net#1115) Handling deletion of Port Channel before deletion of its members (sonic-net#1062) Skip default route present in ASIC-DB but not in APP-DB. (sonic-net#1107) [CLI][PFCWD][Multi-ASIC] Added multi ASIC support to 'pfcwd' CLI (sonic-net#1102) [201911] Multi asic platform config interface portchannel, show transceiver (sonic-net#1087) [drop counters] Fix configuration for counters with lowercase names (sonic-net#1103) Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of PR
Summary:
Fixes # (issue)
In shell script, by default exit code of the last command
in commands connected by pipe is returned. If previous
command returned none zero exit code, the error is
not captured. If ansible run such script in playbook, the
script issue is ignored and ansible is not aware of it.
For example, block in fdb.yml:
fails to detect issue which looks in log like this:
Error message is "Option "-br" is unknown, try "ip -help". But test continues because return code of the script is 0.
The fix is to add "set -o pipefail" in shell scripts. And put the commands embedded in for loop statement to a separate statement. Then the script can exit early and return none zero exit code if the "ip" command failed.
Type of change
Approach
How did you do it?
The fix is to add "set -o pipefail" in shell scripts. And
put the commands embedded in for loop statement
to a separate statement.
How did you verify/test it?
Tested on Mellanox platform.
Any platform specific information?
No
Supported testbed topology if it's a new test case?
NA
Documentation