0

I need to have a bash command's user prompt request to be automatically populated (I am on Windows / Git Bash).

I have the following:

ssh -p [... many other flags and info for connection]

EDIT: The flags I am passing to ssh are:

-p -f -N -L -i

When it is executed, it asks for the user to input a "Verification code"

I have a separate python script that calculates the verification code and then prints it via print command.

#!/usr/bin/env python
import pyotp

secret="mysecret"
totp=pyotp.TOTP(secret)
print(totp.now())

I am trying to concatenate it so that the result of the python script is automatically redirected into the user prompt of the ssh command.

I have tried, with no luck, the following combinations:

ssh -p [...] < ~/totp.sh
ssh -p [...] <<< ~/totp.sh
ssh -p [...] && 0< ~/totp.sh
~/totp.sh | ssh -p [...]
printf '%s\n' ~/totp.sh | ssh -p [...]

However nothing seems to work, as ssh still asks for the user to input the "Verification code". Is there a way to automatically pass it to ssh?

Many thanks.

Link Marston
  • 37
  • 1
  • 8
  • Simply `~/totp.sh | ssh -p [...]` should do what you ask, provided the `ssh` command does not in fact do other things which causes its standard input to be consumed by something else before reaching the program you want to talk to. Basic computer literacy questions are not really suitable for Stack Overflow; I'll see if I can find a good duplicate. – tripleee Mar 25 '22 at 10:57
  • Unfortunately it does not work. I had tried your combination as well, but nope. It is still asking the verification code to be typed in. – Link Marston Mar 25 '22 at 11:02
  • The answer to your actual question "how can I feed the output of `cmd1` as input to `cmd2`" is `cmd1 | cmd2`. Like I allude to in my earlier comment, there may well be things in your `ssh` command line which complicate the matter, but you are not showing those parts, so we can't debug those. It is of course also possible that the target program is not actually reading the verification code from standard input; a common arrangement for password-like prompts is to force the input to be entered from the terminal. In this case, maybe look into Expect (or, from Python, `pexpect`). – tripleee Mar 25 '22 at 11:03
  • Will edit the original question to provide more info. Thank you. – Link Marston Mar 25 '22 at 11:04
  • So the prompt comes from `ssh` itself? Quite likely then you will not be able to pass the input on standard input. Again, probably explore Expect / `pexpect`. You will find a number of duplicate questions about this if you search the site. I added a second duplicate to hopefully at least get you started in the right direction. – tripleee Mar 25 '22 at 11:28
  • Thank you! I'll be looking at wexpect given that pexpect is mostly for linux and I am on Windows/Git Bash – Link Marston Mar 25 '22 at 11:38

0 Answers0