cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1612
Views
10
Helpful
9
Replies

NETMIKO no username command

Jhonata
Level 1
Level 1

I am running a script with Netmiko to erase a username on around 2000 switches, It is working but when the user was already erasing it, netmiko shows an error because is expecting a confirmation to delete, how can I condition expect to have two possible outcomes 

When the user is in the configuration there is not problem, but is not there, netmiko is expecting a string 'confirm'

output=net_connect.send_command('no username XXXXXXXX',
expect_string = r'confirm')
output+=net_connect.send_command('\n', expect_string=r'#') #Confirm command

 

 

1 Accepted Solution

Accepted Solutions

in that case, first, i would get a validation username make a CSV file, use that CSV file as input - user condition to get device IP and username as condition start deleting the username.

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

View solution in original post

9 Replies 9

balaji.bandi
Hall of Fame
Hall of Fame

are you removing the username, which was used to login used in  netmiko ?

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

No i am using another user. I want to remove the username, but if the
username is kot in the config, it will show an error message, because is
expecting a 'confirm', i dont know how to condition that ' expect string

in that case, first, i would get a validation username make a CSV file, use that CSV file as input - user condition to get device IP and username as condition start deleting the username.

 

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

That was the option, thanks for the response, I did create a file with user from the switch and validate the username

Thanks, I managed to solve like this

output1= net_connect.send_command('sh run | in username xxxxx')
net_connect.config_mode()
net_connect.find_prompt()
#Send commands on config mode
with open('users.txt','w+') as d:
user_list = d.write(output1)
with open('users.txt','r') as d: #reading file with users
username = d.read().split()
if os.path.getsize('users.txt') != 0: #if file is not empty
if username[1] in 'xxxxxxxl': #if user is xxxxxx

output=net_connect.send_command('no username g.otero.local',)

expect_string = r'confirm')
output+=net_connect.send_command('\n', expect_string=r'#') #Confirm command
else: print('xxxxxx no found')

Hello,

I am setting up a test lab to verify this, but I think you need something like the below to skip the prompt:

output=net_connect.send_command('no username XXXXXXXX',
expect_string = r'confirm')
output+=net_connect.send_command('\n', expect_string=r'#' #Confirm command
strip_prompt=False,
strip_command=False
)

Hi. I had the same problem and for the last 2 days I've fighting against this issue. I know it might be kind of late but I managed to solve it by using this code:

net_connect.config_mode()
for cmd in config_commands:
     net_connect.send_command_timing(cmd) #this runs "no username X" for each user stored in config_commands
connection.exit_config_mode()
connection.send_command("wr")

it takes a while to execute (around 30 seconds per device) but at least you won't have to delete users manually, which is always prone to errors. I hope you find this answer useful

net_connect or connection was the variable used in

     connection = ConnectHandler(**device)

By mistake my first line says "net_connect". Just keep the same variable. Apologies

what is the issue here?

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: