So I am pretty new to developing so I decided a good way to teach myself would be by creating a small script that configures Cisco switches/routers over SSH. Am a bit stuck on a loop though.
Basically the user has already SSH'd into the switch with username@ip_address and now they need to enter the password. What I need though is for this to loop back to needing the login password if it fails (Because most likely it's because the wrong password was entered)
x = 'false5'
while x != 'true5':
switch_ssh_password = raw_input('What is the Login Password: ')
#Commands to grant entry level access
child.expect('password:')
child.sendline(switch_ssh_password)
if child.expect('%>'):
print "1 - Entry to Switch was Granted"
x = 'true5'
else:
print "1 - Entry to Switch was Denied, Try Again"
x = 'false5'
Now when I get to this user input, I input the password, it hangs for about 30 seconds then comes back with this, I have no idea what's going wrong :(
Traceback (most recent call last):
File "./configcisco.py", line 68, in <module>
if child.expect('%>'):
File "/usr/lib/python2.7/dist-packages/pexpect/__init__.py", line 1418, in expect
timeout, searchwindowsize)
File "/usr/lib/python2.7/dist-packages/pexpect/__init__.py", line 1433, in expect_list
timeout, searchwindowsize)
File "/usr/lib/python2.7/dist-packages/pexpect/__init__.py", line 1535, in expect_loop
raise TIMEOUT(str(err) + '\n' + str(self))
pexpect.TIMEOUT: Timeout exceeded.
<pexpect.spawn object at 0x76a87f70>
version: 3.2
command: /usr/bin/ssh
args: ['/usr/bin/ssh', '[email protected]']
searcher: <pexpect.searcher_re object at 0x76a9ec50>
buffer (last 100 chars): ' \r\n\r\nryan-sw01>'
before (last 100 chars): ' \r\n\r\nryan-sw01>'
after: <class 'pexpect.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 11917
child_fd: 3
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
Without all of your code it's difficult to figure out exactly what is going on. but based on what you've posted your Timing out looking for the shell character, For some additional diagnostics I would change up your code a little: