Posted on 02-12-2013 10:34 AM
Our site recently discovered that stderr output from any extension attribute populated by a script is not being captured. We found this accidentally when we found a syntax error in one of our EA scripts while updating it. We wondered why the JSS wasn't reporting the error, and THEN we wondered how many other EA scripts might have syntax errors.
Knowing that EA output had to be wrapped in <result> and </result> tags, we initially sandwiched the core EA code for each EA script in echo statements that open and close the result tag as follows.
echo "<result>"
... core EA code ...
echo "</result>"
That worked fine for capturing stdout output like the actual values for the extension attribute. What it did not capture was anything written to stderr like syntax errors in the EA script itself that bash might be reporting. To get around this we sandwich the core EA code between result tags as above, but also run the core EA code as a subprocess with stderr from that subprocess redirected to stdout as follows:
echo "<result>"
(
... core EA code ...
) 2>&1
echo "</result>"
This parens make the EA code run in a subprocess, and the "2>&1" redirects stderr to stdout. Using this method we are now able to see when EA script code has syntax errors. For us this uncovered half a dozen extension attribute scripts that had syntax errors or code logic issues that needed to be addressed.
I have reported this to JAMF, but wanted to share with the rest of the community in the mean time.