1

Let's say I have a script that prompts for input, or even let's say I want to do scp your_username@remotehost.com:foobar.txt /some/local/directory and it will prompt me for password (I know that I can add ssh key and such the question is not about that).

How can I write a script or manually inject the response?

So if I have a script which will first ask for password and then ask me to input yes 5 times, how can I do it so that I run it as ./script.sh password yes and it works?

Thanks to anyone for their help.

Quillion
  • 6,346
  • 11
  • 60
  • 97
  • @jkbkot that would work for inputting non passwords too? Such as yes string? If so it is a duplicate, and I will delete this question. – Quillion Jul 22 '14 at 17:08

1 Answers1

1

You may or may not be able to inject the password easily. It depends on how the application expects to read its input.

For the "yes" part of the question though. The answer is the yes command piped to stdin of the process that will ask for input (or expect if the input is more complicated than a single repeated response).

expect might also be able to provide the password when the simpler piping mechanism does not work.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • Let's say that the application expects the input for the password the same way scp expects the input. – Quillion Jul 22 '14 at 17:05