'intercept all stdout, stderr and return code of all commands call in a bash script
I have a brunch of bash scripts. I need to capture the stdout, stderr and return code of individual command call separately inside each bash script.
e.g.
#!/usr/bin/bash
wget https://xyz/1.tar.gz
wget https://abc/2.tar.gz
I want to get the stdout, stderr and error code of the lines wget https://xyz/1.tar.gz and wget https://abc/2.tar.gz separately and analyse the outputs.
I have too many script that I can't edit them one by one. Is there any runner or tool that I can do simple call to the high level script like:
run_and_capture_and_analyse.sh myscript.sh
I've came across the DEBUG trap approach. But the problem is that I still need to edit each script add the trap. Also, there is no way to really capture the outputs.
Thank you
EDITED:
In an ideal situation, I want the outputs (stdout, stderr, return code) to be logged in different file/pipe. I only care external commands, so native controls like echo are not required. Pipe outputs should be captured just like other outputs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
