How can I force quit inside "openssl s_client -connect"?
Asked Answered
W

2

4

I am writing a script that calls the command.

openssl s_client -showcerts -connect server:9999 > out.pem -key key.pem -cert cert.pem -pass pass:password

But it displays an output, I tried adding -quiet but with no luck. Is there a way I can get it so that it won't report to the console. If I run the command in terminal I have to type exit to get out of the connection.

I want this to exit automatically within my script. Is there a way to do that?

Winterwinterbottom answered 1/3, 2011 at 22:2 Comment(3)
Is the problem that there is output to the console, or that the call doesn't exit automatically?Rolandrolanda
It doesn't call exit automatically, is there a way to make it too that?Winterwinterbottom
I am guessing that openssl s_client is executing its dashed commands in order (in this case -showcerts first, then -connect X). I looked for a -quit to add to the end, but cannot find one in the help.Glassful
D
1

The output is possibly being sent to stderr (rather than stdout). It should work if you use >& for the redirection.

Denishadenison answered 2/3, 2011 at 0:44 Comment(4)
OK that stopped the output, but is there a way to make it automatically exit as well?Winterwinterbottom
@Matt: I am not sure about that and currently don't have the necessary certificates in place to test it. But maybe you can change the command to redirect input from a file with the appropriate command: < inputresponse.txtDenishadenison
This could work what is that command called? Could i use a sting instead of a file?Winterwinterbottom
@Matt: It may may simply work if the input file is empty. Or if a line begins with a Q apparently.Denishadenison
H
8

For the automatically exit part, you could do this:

echo | openssl s_client -connect www.google.com:443
Harleigh answered 17/2, 2015 at 17:37 Comment(3)
This seems to work very well. Anyone know why it works? What shell trick does it employ?Glassful
It's not a shell trick. openssl s_client is waiting for user input. It waits for a CR/LF (Enter key). The "echo" piped into openssl simulates that. After receiving that, openssl exits.Transship
You can also openssl s_client -connect www.google.com:443 </dev/null it has the same resultWorthless
D
1

The output is possibly being sent to stderr (rather than stdout). It should work if you use >& for the redirection.

Denishadenison answered 2/3, 2011 at 0:44 Comment(4)
OK that stopped the output, but is there a way to make it automatically exit as well?Winterwinterbottom
@Matt: I am not sure about that and currently don't have the necessary certificates in place to test it. But maybe you can change the command to redirect input from a file with the appropriate command: < inputresponse.txtDenishadenison
This could work what is that command called? Could i use a sting instead of a file?Winterwinterbottom
@Matt: It may may simply work if the input file is empty. Or if a line begins with a Q apparently.Denishadenison

© 2022 - 2024 — McMap. All rights reserved.