Home > other >  How to use paramiko module for remote interaction? Need to enter yes/no
How to use paramiko module for remote interaction? Need to enter yes/no

Time:10-12

I want to achieve is:
A login server using the server B, C to send the file with SCP server B to server, because there are yes/no input, I don't know paramiko module is used to implement?
I wrote a in the server B. Sh is used to test:

Study_shell. Sh
 
#!/bin/bash
Echo "hello, shell! 0130
"Choice="null"
Echo "${choice}
"Read - p "Do you want to build dir? (yes/no) : "the choice
Echo "${choice}
"If [${choice}=='yes']
Then
Echo "OK, we choice yes"
The mkdir we_choice_YES
The else
Echo "We have not choice yes... "
The mkdir we_not_choice_yes
Fi


And then executed in the server A Python script:
 

Def test_paramiko_interact () :
SSH=paramiko. SSHClient ()
SSH. Set_missing_host_key_policy (paramiko. AutoAddPolicy ())
='10.46.169.66' SSH. Connect (hostname, port=22, username='user' and password='PWD')
='sh/home/shell_line study_shell. Sh \ n'
The channel=SSH. Invoke_shell ()
Channel. The send (shell_line)
While True:
RST=STR (channel. Recv (1024))
Print (RST)
If 'yes/no' in RST:
Channel. The send (' yes \ n ')
Time. Sleep (3)
Break
# with SSHClientInteraction (SSH, timeout=2, display=True) as interact:

# stdin, stdout, stderr=SSH. Exec_command (shell_line)
# RST=stdout. Read ()
# SSH. The close ()
# print (RST)
SSH. The close ()


But the result did not function? How to deal with, please?
Thank you very much!

CodePudding user response:

This kind of situation need to call the expect command

CodePudding user response:

reference 1/f, chaotic crocodile response:
this kind of situation need to invoke the expect command

Hello, can give an example of using?
Channel. Expect ()
?
And I this situation is sometimes yes/no, sometimes there will be no (there is no need for the channel. The send (' yes')), the branch how to deal with, please?

CodePudding user response:

Stdin, stdout, stderr=SSH. Exec_command (sh/home/study_shell. Sh \ 'n'. Yes | reload ')
  • Related