2

I am creating a bash script for generating certificates. The openssl command that creates a certificate asks for keyboard input. This is every time the same sequence of keys: seven times [ENTER] followed by two times ['y' + ENTER]. How can I do this programmatically?

Update

I was able to reduce eliminate the required keyboard input using the command line parameters:

  • -config FILE to specify a config file
  • -passin PWD and -passout PWD to specify a password

For more details you can have a look at my experiments. This url is checkout-able with subversion.

1
  • 1
    i think this belongs on server fault
    – user3850
    Apr 7, 2010 at 12:43

4 Answers 4

5

One way to simulate user interaction is expect.

With OpenSSL specifically, you could just write a configuration file that does not require any input for the task you want to perform. (see man 5ssl config)

For a good example of how to script opennssl, see CACerts CSRGenerator script.

2
  • After perusing the man files I learned how to pass the required fields either as command line params or in a config file. Thanks. Apr 7, 2010 at 19:23
  • @StackedCrooked - I have a similar problem. Can you post an answer with the command line or config file params that you used to solve this problem? I think me and others will benefit from it. Nov 10, 2010 at 15:00
1

Since it's asking for keyboard input, just give it something to read.

I suppose yes | your_script would work, otherwise you could just write the following sequence to its input:

\n\n\n\n\n\n\ny\ny\n
0

Expect is pretty good at this kind of thing. Other languages will let you do this (far less conveniently) through their popen-style facilities.

You might be able to pipe the characters in as @tusbar suggests, but tools like openssl may insist on you typing it in (something Expect gets around by setting up pseudo-terminals).

0

You can also use a here document to include input directly in your bash script:

interactive-program <<LimitString
command #1
command #2
...
LimitString

(But the configuration file option suggested by @hop is still the best idea).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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