0

I have an endpoint that returns the following plain text:

openssl genrsa -out server.key 2048
openssl req -new -sha256 -key server.key -out server.csr

but after I run it like this:

curl -sSf https://.../ | bash -

it asks Country Name (2 letter code) [XX]: but then immediately runs the second command which causes an error and goes back to the prompt. How can I make it wait for the user to enter all the fields asked by command 1 and then run command 2?

The reason I am doing it like this is because I am creating a service that reads plain text from a curl call and pipes it to bash; a sort of automated scripting from a remote resource.

6
  • It would automatically pause for stdin if executed as posted. Maybe you call it in such a way that stdin is not available to be waited on? Commented Nov 5, 2015 at 2:51
  • Sorry, I left something important out. Updating the question. Commented Nov 5, 2015 at 2:52
  • stdin is consumed by bash in this case. Tell us why you run the script in such a twisted way. Commented Nov 5, 2015 at 2:54
  • I actually run it like curl -sSf https://.../ | bash - as that is an internal service I created for running automated scripts. Commented Nov 5, 2015 at 2:54
  • Use process substitution bash <(curl blah blah). Commented Nov 5, 2015 at 2:55

1 Answer 1

3

When the content of a script is piped into bash, stdin is connected to the pipe rather than the tty, so the script cannot read from a tty, and actually can't milk anything out of stdin for that matter (will always get EOF), because stdin is already exhausted by bash. It is possible to exhaust stdin multiple times within the script by closing and reconnecting it (for instance, see this question), but for any generated script content, you can always use process substitution to free up stdin:

bash <(curl -sSL http://git.io/vlhFL)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, exact solution I needed.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.