Forum Discussion
I'd suggest using before the first cli.expect statement, in case that first expect statement is the one expecting the "#" and never getting it back from the device. You might want to put a sleep statement (sleep(n) where n is the number of milliseconds the script should wait before executing the next line) between logging in and doing the println(cli.before()) so that the device has a chance to send something back to you after logging in.
A lower level way to work through this is to replicate the activity of the script using your own SSH client (e.g. putty on Windows or terminal in Linux/Mac). Log in using the same credentials, make a note of what get sent to you when you log in. After providing the username and password, are you sent directly to the prompt? How do you recognize what the prompt is? Think about how you use your human brain to understand that the device is waiting for your input. Then, what command do you send and what do you expect back? When you get that back, how do you (as a human) recognize that the device has sent you everything it's going to send? Usually because it returns to the prompt. You need to teach your script not only to send the command but also to recognize the output coming back from the device and know when the device is done sending the response back and is waiting for another command.
In this case, the script (trying to emulate human behavior) is looking for a #, likely because the prompt probably uses something like "my-cisco-ise# " as the prompt.
Welcome to the deep end where you get to learn groovy and expect in one step. ?
Related Content
- 2 years ago
- 4 months ago
- 2 years ago