question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dealing with commands that do not return a prompt

See original GitHub issue

I have looked all over and can’t seem to find an answer that works consistently.

I have a script that will run iperf tests from router to router and I am having issues getting it to be consistent. I am running at the enable prompt with “guestshell run sudo iperf3 -s”. It either says it is running and does not return a prompt or gives an error and returns a prompt.

My issue comes into play when the script issues the above command but it doesn’t return the output I am looking for to continue or not before it moves to the next command. I have tried different variations on send_commands_timing with delay_factor and max_loops set but it isn’t consistent.

Below are snips from both the debug log and my code. Let me know if I need to submit more detail.

----------------------Relevant Code--------------------

            iperf_status = att_connection.send_command_timing('guestshell run sudo iperf3 -s',
                                                              delay_factor=8, max_loops=600) # initial run of iperf
            if 'Server listening' in iperf_status: # check if it's running
                return (iperf_status, iperf_server, att_connection, a_host_name)
            else:
                # server wasn't listening, stop and then restart guest shell and try again
                print(f'Restarting guestshell on {a_host_name}, please wait.')
                att_connection.send_command_timing('guestshell disable', delay_factor=2) #force close guestshell
                time.sleep(5)
                att_connection.send_command_timing('guestshell enable', delay_factor=2) # restart guestshell
                time.sleep(5)
                iperf_status = att_connection.send_command_timing('guestshell run sudo iperf3 -s', delay_factor=2) # try again
                if 'Server listening' in iperf_status: # see if it's running and exit function if it isn't
                    print(f'Successfull restart of guestshell on {a_host_name} and iperf successfully started')
                    return (iperf_status, iperf_server, att_connection, a_host_name)
                else:
                    return(f'Error encountered after attempted restart of guestshell on: {iperf_status}',iperf_server, a_host_name)

-----------------------Debug log ---------------------- DEBUG:netmiko:write_channel: b’guestshell run sudo iperf3 -s\n’ DEBUG:netmiko:read_channel: guestshell run sudo iperf3 -s # initial run sets variable to null

DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b’guestshell disable\n’ # fails iperf_status check - null DEBUG:netmiko:read_channel: ^@----------------------------------------------------------- # output from initial run Server listening on 5201

guestshell disable # script thinks it didn’t run

DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel:

repeat of initial run where it fails check and thinks it didn’t run a second time so it exits script

As you can see, the command did run as expected initially but output was returned after issuing the command to forcefully exit the guestshell because the value of iperf_status is nothing (debug shows iperf_status = ‘’).

I have also tried send_command with expect_string=‘[expected output]’ but since I could get one of three outputs (null, running, unable to run) if it gets anything but what I specify it raises an exception, which is expected I would think.

Is there a way to make the send_command_timing wait just a bit longer aside from delay_factor and/or max_loops to actually capture the output I am looking for? Running manually, the command takes 2-5 seconds to complete so I think a delay of 8 would be sufficient.

What am I missing?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Chuck-Thorntoncommented, Jun 2, 2022

That was the answer. I kinda figured I was missing something somewhere.

Regular expressions are not my forte.

Thanks again for the assistance

1reaction
Chuck-Thorntoncommented, Jun 2, 2022

Thank you for the response, I will try it and let you know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to have back the command prompt after calling an ...
In terminal I just type firefox and then Firefox starts, but I can not return to command mode anymore. How can I come...
Read more >
The Unresponsive Terminal - Learning the UNIX ... - O'Reilly
The Unresponsive Terminal · Press the RETURN key. · If you can type commands, but nothing happens when you press RETURN, try pressing...
Read more >
nohup in "bash script -s ..." do NOT return prompt
I'm using bash to upload springboot package and restart it, but commands do NOT return prompt. restart.sh:
Read more >
script submitted using ssh does not return to command prompt
I am writing a menu script and one of the options is to access a Command Prompt and return to the menu via...
Read more >
Multitasking from the Linux Command Line + Process ...
An example of a foreground job that won't return you to the command prompt until it is finished is the zip command. Imagine...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found