I am running bash scripts and executing bash commands on remote systems using Connectwise Automate (formerly LabTech). These systems are both Linux and MacOS. Connectwise Automate (CWA) has some peculiar behavior with regards to *nix systems, wherein if a command or expression exits with a status code of 0 all output, regardless of stream (stdout or stderr), is replaced with the word "OK". When a non-0 exit status is returned the output is properly displayed in the CWA's remote terminal and script output. I have not received definitive confirmation that the output replacement behavior is based on exit code, however I believe it to be highly likely.
For a simplistic example,
echo "Test" returns
ls ./no/such/directory yields the appropriate exception. This is a long-standing issue with CWA and working with the vendor yields no workarounds or positive results without piping the command output to a file on disk and reading that file with a function particular to CWA. That yields inconsistent results, however, as often the command output that gets written to file is simply
What I've tried
I've found and attempted many possible solutions. I found this question, specifically geared towards
less, and was reliant on
-K argument. I attempted to adapt part of the solution with no success invoking
bash -c and
trap, though my implementation could have been incorrect. I also attempted something along the lines of
echo "Test" && false, which returns
OK, likely (in my mind) due to the first command returning with an exit code of 0 before evaluating
Is it possible to "coax" (so to speak) arbitrary utilities, particularly when invoked via
sh, into returning with an exit status of my choosing, or otherwise any non-0 exit status, and still have a given utility's output hit stdout/stderr?