cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2573
Views
0
Helpful
5
Replies

Changing router configuration from whithin guestshell

kasper123
Level 4
Level 4

Is it possible to issue commands to the router from guestshell?

I know that I can use "dohost" to read outputs from the router like dohost "show clock" but is it possible to enter configuration mode and issue commands from whithin the guestshell?

Regards.

 

1 Accepted Solution

Accepted Solutions

kasper123
Level 4
Level 4

If someone else encounters this problem, I managed to find a way to issue commands to the cli from inside the guestshell.

Built in into the guestshell is the cisco cli python module which can be used to read items from the cli like one would do with the dohost command but you can also send configuration commands to the device.

A simple show command:

[guestshell@guestshell ~]$ python3
Python 3.6.8 (default, Nov 21 2019, 19:02:24) 
[GCC 8.3.1 20190507 (Red Hat 8.3.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cli import *
>>> cli("show clock")
'12:14:53.696 CEST Mon Sep 7 2020\n'
>>> 

You cal also issue multiple configuration commands. For instance we could enter configuration mode and send two commands to configure two usernames:

>>> cli("conf t;username ttt privi 15 pass aaa;username aaa priv 5 pass bbb")
'\n WARNING: Command has been added to the configuration using a type 0 password. However, type 0 passwords will soon be deprecated. Migrate to a supported password type\n WARNING: Command has been added to the configuration using a type 0 password. However, type 0 passwords will soon be deprecated. Migrate to a supported password type\n'
>>>

We can also enter config mode, send configuration commands, exit config mode and save the configuration.

>>> cli("conf t;username ttt privi 15 pass aaa;username aaa priv 5 pass bbb;exit;wr mem")
'\n WARNING: Command has been added to the configuration using a type 0 password. However, type 0 passwords will soon be deprecated. Migrate to a supported password type\n WARNING: Command has been added to the configuration using a type 0 password. However, type 0 passwords will soon be deprecated. Migrate to a supported password type\nBuilding configuration...\n[OK]\n'
>>> 

Hopefully this will help someone looking to do the same.

 

View solution in original post

5 Replies 5

Sergiu.Daniluk
VIP Alumni
VIP Alumni

Hi @kasper123

Try this:

[guestshell@guestshell ~]$ dohost "conf t ; cdp timer 13 ; show run | inc cdp"

Stay safe,

Sergiu

Hi,

I'm getting a systnax error.

[guestshell@guestshell ~]$ dohost "conf t ; cdp timer 13 ; show run | inc cdp"
Syntax error while parsing 'conf t ; cdp timer 13 ; show run | inc cdp'.Cmd exec error.
[guestshell@guestshell ~]$ 

What router/software module do you have?  The cmd I shared works on Nexus as it supports to concatenate multiple commands.

Try this then:

[guestshell@guestshell ~]$ dohost "conf t"  "cdp timer 13" "show run | inc cdp"

 

Cheers,

Sergiu

Now it shows this

[guestshell@guestshell ~]$ dohost "conf t"  "cdp timer 13" "show run | inc cdp"
Syntax error while parsing 'cdp timer 13'.Cmd exec error.

cdp timer 13

[guestshell@guestshell ~]$ 

I'm getting the same error on a cisco 1111 router and Catalyst 9300 switch.

kasper123
Level 4
Level 4

If someone else encounters this problem, I managed to find a way to issue commands to the cli from inside the guestshell.

Built in into the guestshell is the cisco cli python module which can be used to read items from the cli like one would do with the dohost command but you can also send configuration commands to the device.

A simple show command:

[guestshell@guestshell ~]$ python3
Python 3.6.8 (default, Nov 21 2019, 19:02:24) 
[GCC 8.3.1 20190507 (Red Hat 8.3.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from cli import *
>>> cli("show clock")
'12:14:53.696 CEST Mon Sep 7 2020\n'
>>> 

You cal also issue multiple configuration commands. For instance we could enter configuration mode and send two commands to configure two usernames:

>>> cli("conf t;username ttt privi 15 pass aaa;username aaa priv 5 pass bbb")
'\n WARNING: Command has been added to the configuration using a type 0 password. However, type 0 passwords will soon be deprecated. Migrate to a supported password type\n WARNING: Command has been added to the configuration using a type 0 password. However, type 0 passwords will soon be deprecated. Migrate to a supported password type\n'
>>>

We can also enter config mode, send configuration commands, exit config mode and save the configuration.

>>> cli("conf t;username ttt privi 15 pass aaa;username aaa priv 5 pass bbb;exit;wr mem")
'\n WARNING: Command has been added to the configuration using a type 0 password. However, type 0 passwords will soon be deprecated. Migrate to a supported password type\n WARNING: Command has been added to the configuration using a type 0 password. However, type 0 passwords will soon be deprecated. Migrate to a supported password type\nBuilding configuration...\n[OK]\n'
>>> 

Hopefully this will help someone looking to do the same.