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.

logs get mixed when using `expect_string` inside `send_command()`

See original GitHub issue

Hi! I’m trying out the new version of netmiko 4.1.0. I’m upgrading a set of tools that I was using with netmiko 3.4.0. I’m using device type nokia_sros with a range of timos versions (7.x, 9.x, 16.x, 21.x).

When using send_command() with show-like commands, I used to store the received outputs both in a json file and a plain text file.

These are a snippet of the commands I’m sending to the router:

# SCRIPT_NONO_START
/environment no more
/show router bgp summary
/show router interface
/show service sdp
/show service sdp detail

This is how I store the recevied output:

try:
    for cmd in cmdList:
        rx        = conn2rtr.send_command(cmd, expect_string=r"#", cmd_verify=True, read_timeout=10)
        outputTxt = outputTxt + '\n' + cmd + '\n' + rx
        outputJson[cmd] = rx
    outputReason = ""
    runStatus    = 1
except Exception as e:
    outputTxt    = ''
    outputReason = str(e)
    runStatus    = -1

But here is a problem. If I enable the expect_string inside the send_command(), then my ouput both in the json or the text file, gets scrambled. The output on the left corresponds to the case where exptect_string is enabled; on the right, I’m not using it. You can see on the left how the sent commands are being repeated, like echoed.

image

This is a snippet of the json file. Look how the values for each key, are mixed.

image

I was using the expect_string before, to speed up things, but the output gets corrupted.

However, everything seems to be allright if I do not use the expect_string.

Any hint?

thanks!

Lucas

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
laimarettocommented, Jun 27, 2022

Yes, that was it … thank you …

1reaction
ktbyerscommented, Jun 27, 2022

Have you tried:

r"#\s+$"

In other words, are you sure there is no whitespace between the # and the end-of-line?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Amazon CloudWatch Logs for Run Command
Specifying CloudWatch Logs when you send commands ... If you run commands by using the AWS CLI, specify the cloud-watch-output-config section in your...
Read more >
SEND command operands - IBM
Specifies the message is sent to the user ID associated with the issuer of the SEND command. If * is used with a...
Read more >
Viewing SSM Agent logs - Amazon Systems Manager
View log files about commands, scheduled actions, errors, and health status by manually connecting to a managed node or by automatically sending logs...
Read more >
Use Expect in a Bash script to provide a password to an SSH ...
Mixing Bash and Expect is not a good way to achieve the desired effect. I'd try to use only Expect: #!/usr/bin/expect eval spawn...
Read more >
How To Troubleshoot Common Apache Errors - DigitalOcean
There are three main commands, and a set of common log locations that you can use to get started troubleshooting Apache errors.
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