Ubuntu – how to save stderr and stdout to a file in ubuntu

stderrstdinUbuntu

when i run

echo "invalid crt" | openssl x509 -noout -modulus | openssl md5 &>> error.log

this show below error

unable to load certificate
139903857870496:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:703:Expecting: TRUSTED CERTIFICATE

and "(stdin)= d41d8cd98f00b204e9800998ecf8427e" content in error.log

I want to save stdin with error (how to save terminal error text into error.log too)

how can i do that ?

Best Answer

When you do

echo "invalid crt" | openssl x509 -noout -modulus | openssl md5 &>> error.log

the only the stderr of the second openssl command is written to error.log. Use this:

echo "invalid crt" | (openssl x509 -noout -modulus | openssl md5) &>> error.log

so that both openssl processes are run in a subshell, and the subshell's stderr is redirected together with the stdout to error.log.