0

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 ?

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

2 Answers2

1

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.

wurtel
  • 3,864
  • 12
  • 15
  • 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 06:58
  • I personally always do >> error.log 2>&1 but I was following the OP's lead here. – wurtel May 20 '16 at 07:00
  • Me too, and that is **also** bash-specific (well, Bourne-flavoured-shell-specific). – MadHatter May 20 '16 at 07:01
0

Use cmd &> file.log :

$ blahblah &> /tmp/blah.log
$ echo $?
127
$ 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
cuongnv23
  • 230
  • 3
  • 9