ktbyers / netmiko

Multi-vendor library to simplify Paramiko SSH connections to network devices
MIT License
3.59k stars 1.3k forks source link

use of expect_string with Aruba wireless controller #1018

Closed vigilne closed 5 years ago

vigilne commented 5 years ago

I am trying to use netmiko to automate my backups of Aruba wireless controllers. The challenge is when I initiate the backup it does not return a trailing prompt but instead prompts for password for ftp. I have attempted to use the expect string to handle this but not sure if I am using it incorrectly.

My code is below:

from netmiko import ConnectHandler

wlc01 = { 'device_type': 'aruba_os', 'ip': '172.16.9.15', 'username': 'admin', 'password':'password', }

net_connect = ConnectHandler(**wlc01)

net_connect.send_command('backup flash', delay_factor=2)

cmd = 'copy flash: flashbackup.tar.gz ftp: 172.16.1.10 ftpuser /backups flashbackup.tar.gz' pwd = 'password' net_connect.send_command(cmd, expect_string=r':') net_connect.send_command(pwd)

net_connect.disconnect()

The output I get when running the code is here:

Python 3.6.6 (default, Sep 12 2018, 18:26:19) [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux Type "help", "copyright", "credits" or "license" for more information.

from netmiko import ConnectHandler wlc01 = { ... 'device_type': 'aruba_os', ... 'ip': '172.16.9.15', ... 'username': 'admin', ... 'password':'password', ... } net_connect = ConnectHandler(**wlc01) net_connect.send_command('backup flash', delay_factor=2) 'Please wait while we tar relevant files from flash...\nPlease wait while we compress the tar file...\nFile flashbackup.tar.gz created successfully on flash.\nPlease copy it out of the switch and delete it when done.\n' cmd = 'copy flash: flashbackup.tar.gz ftp: 172.16.1.10 ftpuser /backups flashbackup.tar.gz' pwd = 'password' net_connect.send_command(cmd, expect_string=r':') 'Password:' net_connect.send_command(pwd) " ^\n% Invalid input detected at '^' marker.\n"

Any guidance is appreciated.

ktbyers commented 5 years ago

You should be able to use a pattern similar to this:

https://github.com/ktbyers/netmiko/blob/develop/COMMON_ISSUES.md#show-commands-that-prompt-for-more-information

vigilne commented 5 years ago

Using the send_command_timing worked out much better. thank you.

ktbyers commented 5 years ago

No worries @vigilne