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 ?

  • Title is stdout and stderr, text says stdin and stderr. I'm presuming the title is correct? – wurtel May 20 '16 at 6:44

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.

| improve this answer | |
  • This is bash-specific. That's not a bad thing (+1 from me, anyway) it's just worth noting for the benefit of, eg, future tcsh users reading this question. – MadHatter May 20 '16 at 6:58
  • I personally always do >> error.log 2>&1 but I was following the OP's lead here. – wurtel May 20 '16 at 7:00
  • Me too, and that is also bash-specific (well, Bourne-flavoured-shell-specific). – MadHatter May 20 '16 at 7:01

Use cmd &> file.log :

$ blahblah &> /tmp/blah.log
$ echo $?
$ cat /tmp/blah.log 
bash: blahblah: command not found

To append, use cmd >>file.log 2>&1

$ wrongcmd >>/tmp/blah.log 2>&1
$ cat /tmp/blah.log 
bash: blahblah: command not found
bash: wrongcmd: command not found
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.