Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
6

Quick Netmiko question

Hi,

I apologize if this is a simple issue to fix, but I wasn't able to find the answer to this after which is why I'm posting here.

I'm trying to use the .send_command to delete files from flash on cisco ios. Here is the output I have

>>> output = net_connect.send_command('delete flash:cat3k_caa-base.SPA.03.03.02SE.pkg')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xxxx/.local/lib/python2.7/site-packages/netmiko/base_connection.py", line 1051, in send_command
    search_pattern))
IOError: Search pattern never detected in send_command_expect: XXX\XXX\XXX\#

I think the send_command is expecting to see the hostname which I edited out to (XXX\XXX\XXX)after sending a command, but the issue with the delete command is that it prompts for confirmation. Does anyone know how to get around this?

Thanks

12 comments
80% Upvoted
What are your thoughts? Log in or Sign uplog insign up
level 1
3 points · 3 months ago

It's probably stuck at a prompt. The prompt probably looks something like

Delete filename [your filename]?

Do something like this instead to get through the prompt

net_connect.send_command('your command', expect_string=']?')

level 2

I didn't realize you could change the expect parameter!

level 1

This means the command is taking longer than netmiko will wait by default.

You need to adjust the delay_factor or max_loops in your send_command call. Check here: http://netmiko.readthedocs.io/en/latest/classes/base_connection.html

level 2
Original Poster1 point · 3 months ago

Hmmm, I just increased delay_factor to 3 and max_loops to 1000, a single command took several minutes to run but I this error

IOError: Search pattern never detected in send_command_expect: Delete\ flash\:\/cat3k\_caa\-base\.SPA\.03\.03\.02SE\.pkg\?\ \[confirm\]
level 3
#SquadGoals: Nine 5's uptime3 points · 3 months ago

Oof, a cat3k.

The error is pretty strasightforward, the send_command_expect you're using doesn't find that search pattern. This is likely because your old cat3k isn't responding fast enough/is CPU pegged/doesnt have reserved memory for admin sessions/can't handle ssh with everything else it's doing.

Please read this thread to the bottom (first hit on right click > google): https://github.com/ktbyers/netmiko/issues/292 specifically the last 3 or so comments.

EDIT: Scrub your code and pastebin it here so I can look at it, if that doesn't fix it.

level 4
scriptin' and sploitin'1 point · 3 months ago

/u/SS324

how big is the file?

level 4
Probably drunk | Moderator1 point · 3 months ago

old cat3k

Why do you suspect it's old? Cat 3Ks are still a current series. It's an IOS-XE image based on the version number, which makes it a 3650 or 3850. Not old by any stretch of the imagination.

level 5
#SquadGoals: Nine 5's uptime1 point · 3 months ago

Miiiiiiightve been getting catos and cat3k mixed up. Today was a "roll out bitlocker without blowing up the org" day so I wasn't paying attention ;)

level 3

Right, so you're trying to do an interactive command and the switch is sending back a question, to which you'll need to respond.

You can either specify a "/force /recursive" with the command (such as "delete /force /recursive flash:/file.ext" or you can specify an "expect_string" in your send_command call to match what the switch will send back when you send your initial delete request.

The way Netmiko generally works is that when you log in to the device, it saves the initial prompt. When you run send_command, it continually looks at the packet buffer coming back until it sees that initial prompt again. Your delete command doesn't return that initial prompt.

It helps to look at the source code. The function you want to look at is send_command_expect.

level 1

send_command_expect might be what you need?

https://github.com/ktbyers/netmiko#for-long-running-commands-use-send_command_expect

Otherwise, send_command_timing might be a good fit?

https://github.com/ktbyers/netmiko/issues/330

output = net_connect.send_command_timing("vpn-sessiondb logoff ipaddress 10.1.2.2")
if 'Do you want to' in output:
    output += net_connect.send_command_timing("y")
level 1

I personally use the /force /recursive command when deleting files on Cisco IOS. This is useful for deleting folders taking up space without creating a custom process.

Example:

"delete /f /r " + directory + ":/" + image

Community Details

127k

Subscribers

879

Online

###Enterprise Networking Routers, switches and firewalls. Network blogs, news and network management articles. Cisco, Juniper, Brocade and more all welcome.

Create Post
r/networking Rules
1.
Rule #1: No Home Networking.
2.
Rule #2: No Certification Brain Dumps / Cheating.
3.
Rule #3: No BlogSpam / Traffic re-direction.
4.
Rule #4: No Low Quality Posts.
5.
Rule #5: No Early Career Advice.
6.
Rule #6: Educational Questions must show effort.
Cookies help us deliver our Services. By using our Services or clicking I agree, you agree to our use of cookies. Learn More.