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.

Running send_command with variable not working.

See original GitHub issue

What am I doing wrong below. I am trying to run a show run command from the list intfaces using the variable x. I get no output.

for line in ipfile:
    device['ip']=line.strip()
    print("Connecting to Device " + line)
    net_connect = ConnectHandler(**device)
    time.sleep(2)
    print ("Checking Interface Configurations")
    intfilter = net_connect.send_command("sh run | i Gi.")
    striplist = intfilter.rstrip()
    intfaces = []
    intfaces.append(striplist)
    for x in intfaces:
        intconfig = net_connect.send_command("sh run " + x)
        print(intconfig)

****the indentation doesn’t seem to show up

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nlspearscommented, Oct 4, 2019

That worked! It is now spitting out the configs of each interface. Thank you!

0reactions
ktbyerscommented, Oct 4, 2019

It is a one element list…so you have one great big string stuffed inside the list.

When you loop through this, your loop variable x will be that great big string.

You probably want to use splitlines() to break up the string i.e. instead of using .rstrip() do something like:

    intfilter = net_connect.send_command("sh run | i Gi.")
    striplist = intfilter.strip()
    # no append--this will create a list
    intfaces = striplist.splitlines()
Read more comments on GitHub >

github_iconTop Results From Across the Web

expect command variable with pipes and special characters ...
The command I want to run in the remote server is: ... So, the problem is that I want to execute a multiple...
Read more >
sendCommand or postUpdate does not work in OH 2.1 - why?
I just try to upgrade from openhab 1.8 to 2.1. In OH 1.8 I have over 100 rules with sendCommand or postUpdate. In...
Read more >
How can I use " inside expect send command with variable
I have used the /usr/bin/expect to SSH into my other system and execute some commands using send. Here is command that need to...
Read more >
Working with parameters using Run Command commands
Run parameters by using either Run Command on the Systems Manager console or the AWS CLI. ... aws ssm send-command \ --document-name "AWS-RunShellScript" ......
Read more >
docker run - Docker Documentation
docker run: The `docker run` command first `creates` a writeable container ... This will not work, because by default, most potentially dangerous kernel ......
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