#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0

    Cool PExpect doesn't work with some Cisco?


    Hi,

    I'm trying to get some information from Cisco 2960X switches.

    This simple script works on a 3560 returning the correct output, but on a 2960 it just returns empty "string".

    child = pexpect.spawn('ssh %s@%s' % (USERNAME, DEVICE_IP))
    child.timeout = 10
    child.expect('Password:')
    child.sendline(PASSWORD)
    child.expect('#')
    # child.sendline('terminal length 0')
    # child.expect('#')
    child.sendline('show inventory')
    child.expect('#')
    print(child.before.decode('utf-8'))
    child.sendline('exit')

    If I print child.after I get the #, so I guess the login is successful.

    Anyone have some experience with this or a clue on what is wrong?


    --
    Ronni
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    3
    Rep Power
    0
    Got it working.

    There was a banner in the configuration with the # sign, the same that the script expects, which maked the script fail.

    --
    Ronni
  4. #3
  5. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,861
    Rep Power
    509
    thank you
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo