Skip to content
Advertisement

Pass input/variables to command/script over SSH using Python Paramiko

I am having issues passing responses to a bash script on a remote server over SSH.

I am writing a program in Python 3.6.5 that will SSH to a remote Linux server. On this remote Linux server there is a bash script that I am running which requires user input to fill in. For whatever reason I cannot pass a user input from my original python program over SSH and have it fill in the bash script user input questions.

main.py

JavaScript

SSH.py

JavaScript

The final /xxxxxx in class Connect is the remote script that is launched. It will open a text response awaiting a format such as

What is your name:

and I cannot seem to find a way to properly pass the response to the script from my main.py file within the class Connect.

Every way I have tried to pass name as an argument or a variable the answer seems to just disappear (likely since it is trying to print it at the Linux prompt and not within the bash script)

I think using the read_until function to look for the : at the end of the question may work.

Suggestions?

Advertisement

Answer

Write the input that your command needs to the stdin:

JavaScript

(You will of course need to propagate the name variable from module to sendCommand, but I assume you know how to do that part).

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement