Operations Orchestration Support and News Forum
Showing results for 
Search instead for 
Do you mean 

ssh command stderr, stdout and exit code

Occasional Contributor

ssh command stderr, stdout and exit code



I'm trying to capture standard error, standard out and the exit code of a unix program in an SSH Command flow step.  Here's my unix script for testing:



echo "standard out"
echo "standard error" >&2

exit 7

 The script executes fine using the SSH Command step, but the results are munged.  Here's the raw result:


{returnCode=-1;STDERR=;returnResult=;Result=;sessionId=iconclude4728939292462036583;STDOUT=standard out
standard error

 You can see that the Result and returnResult are blank and the standard error was combined with standard out.  The error code (7) is nowhere to be seen.  I have a unix process that returns error codes from 0 - 255 and different action needs to be taken based on the error code combined with standard error.


This is with OO version 9.0.7


Occasional Contributor

Re: ssh command stderr, stdout and exit code


Ok, I solved my own problem by writing a wrapper script that returns easily parseable XML.  There are probably a thousand ways to do this and mine is not the most elegant, robust or complex.  But, it works for me.


Filename: oowrap.sh


# Wrapper script for running unix commands from HPOO Flow.
#  - Returns easily parseable XML.
#  - Separates STDOUT and STDERR.
#  - Captures process id numbers.
#  - Captures exit code.
# Useage:
#  oowrap.sh /path/to/command -any -argument -you -want

progname=`echo $1 | awk -F\/ '{ print $NF }'`

$* 2>$stderr 1>$stdout &
wait $cmdpid

cat - << XML
<exec bashversion="$BASH_VERSION">
cat $stdout
cat - << XML
cat $stderr
cat - << XML

rm $stderr
rm $stdout

if [ $exitval -ne 0 ]
        exit 1


Using this is simple enough, just apply the "XML Get Element Value" result filter to the stdout result.




It seems to me like it would be easy to include this functionality in the "SSH Command" flow step, would be a lot cleaner than what I'm having to do here.