3: Executing Interactive Commands in Python through Paramiko Part-2
Why Stack Overflow recommends it
Stack Overflow users link it when answering how to send input to or read prompts from commands run over SSH with Paramiko, since exec_command cannot handle interactive prompts.
Recommended by 3 people across 3 different months, 2015 to 2017.
What it is
A 22-minute tutorial from TheIPSchool, part 2 of a series, showing how to run interactive commands over SSH in Python with Paramiko. It uses a network-device example (copying a file from a TFTP server) that prompts for input, and demonstrates driving the session through a shell channel.
What people said
Strong rec Mino_e · 2015-01 · Stack Overflow · on “Running interactive commands in Paramiko”
The question is old but for the people who still come here via google search i want to give them this.The key is to get your own **channel** Executing Interactive Commands in Python through Paramiko Part 1 [LINK] Executing Interactive Commands in Python through Paramiko Part 2 [this video] In this two videos it's explained how to run interactive commands via paramiko especially the second video is great and probably what you need.
Recommends colin0117 · 2016-05 · Stack Overflow · on “Read remote output and respond using paramiko (SSH.execute)”
@leoluk - yep, I understand your problem, both those recommended solutions won't work. The problem, as you said, with exec_command is that you can only read the output once the command completes. So, if you wanted to remotely run the command rm -i * , you won't be able to read which file is to be deleted before you can respond with a "yes" or a "no". The key here is to use invoke_shell. See this youtube link - [this video] - this helped and got me going.
Recommends Ghana · 2017-04 · Stack Overflow · on “Not able to execute remotely placed ssh script with parameter using paramiko ssh client”
I found out answer to my own query on a video over [this video] for interactive commands. Some how it was problem with command termination and client was unable to find end of it as it is not unix/system defined command ("system commands like ls -lrt, cd, grep works perfectly fine with client") So i tried channel like below code to execute the shell script located on server which needs parameter- def runScripts(): parameter1 = 1000 client.connect('mysite.com', username='user', password='pass') channel = client.invoke_shell() print ("Logged in into Site server") channel.send("cd parent_folder/Sub_folder/script_folder; ./script1.sh %s" % parameter1) print ("Script executed perfectly") client.close(