08-28-2020 05:25 AM - edited 08-28-2020 05:45 AM
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.
Solved! Go to Solution.
09-07-2020 03:19 AM
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.
08-28-2020 05:46 AM
Hi @kasper123
Try this:
[guestshell@guestshell ~]$ dohost "conf t ; cdp timer 13 ; show run | inc cdp"
Stay safe,
Sergiu
08-28-2020 05:51 AM
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 ~]$
08-28-2020 06:02 AM
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
08-28-2020 06:05 AM
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.
09-07-2020 03:19 AM
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.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide