0

I am currently automating CLI command testing with paramiko in python. After successfull connection with ssh and running one command, an interactive session opens up in CLI itself, which is asking to enter choice from 1-10 and 'e' as exit. So how can I pass these keys into cli and press enter to navigate to that menu?

output = ''
strings = []
ssh = paramiko.SSHClient()

# Automatically add the host key to the local SSH key store
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# Connect to the remote host with a password
ssh.connect(ip, username=username, password=password)
channel = ssh.invoke_shell()
# If su is True, login as root user
if su:
    channel.send('su - root\n')
    channel.send(supasswd+'\n')
command = '''ls -ltr
su -xyzconfig
1'''  
channel.send(command)
while channel.recv_ready():  # monitoring process 
    strings.append(channel.recv(65535).decode())
    time.sleep(2)
output =''.join(strings)
strings = []

Now I could extract the output till su -xyzconfig. But after that in command shell(if run manually), It asks to Enter choice as a keyboard key to navigate inside the menu. But here I am unable to send "1" as a key. So is there something else which I can do to navigate in the menu?

Menu which is appearing when I am manually entering commands

10
  • "Not working" is not working as a problem description. + What is the command like? Aren't you missing \n there? Commented Feb 27, 2024 at 12:13
  • please post code in text format instead of screenshot. Commented Feb 27, 2024 at 14:49
  • Also your screenshot does not match your text code. Commented Feb 27, 2024 at 15:49
  • Edited......I am already taking \n into the account. Just want to know how to send keyboard key to navigate. I also tried sending unicode but couldn't navigate. I have attached image of the menu which is appearing in CLI. Commented Feb 28, 2024 at 9:33
  • I do not think you can send three lines of input like this at once. Some of your input is probable discarded. Shell should not be automated this way. See stackoverflow.com/q/51493317/850848 – If you have no other option, I'd try try "sleeping" a bit between the individual inputs. Or better, waiting for desired output, before sending another input. Commented Feb 28, 2024 at 10:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.