forked from ktbyers/netmiko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_command_prompting.py
38 lines (33 loc) · 1.02 KB
/
send_command_prompting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
from netmiko import ConnectHandler
from getpass import getpass
cisco1 = {
"device_type": "cisco_ios",
"host": "cisco1.lasthop.io",
"username": "pyclass",
"password": getpass(),
}
command = "del flash:/test3.txt"
net_connect = ConnectHandler(**cisco1)
# CLI Interaction is as follows:
# cisco1#delete flash:/testb.txt
# Delete filename [testb.txt]?
# Delete flash:/testb.txt? [confirm]y
# Use 'send_command_timing' which is entirely delay based.
# strip_prompt=False and strip_command=False make the output
# easier to read in this context.
output = net_connect.send_command_timing(
command_string=command, strip_prompt=False, strip_command=False
)
if "Delete filename" in output:
output += net_connect.send_command_timing(
command_string="\n", strip_prompt=False, strip_command=False
)
if "confirm" in output:
output += net_connect.send_command_timing(
command_string="y", strip_prompt=False, strip_command=False
)
net_connect.disconnect()
print()
print(output)
print()