5

I just learned about Cisco IOS.sh and found that you're able to run commands similar to UNIX based systems on Cisco devices.

First question: Is IOS.sh router or switch specific? Or are they able to be used for both types of devices as long as the firmware version is 15.1 or later?

Second Question: Now that IOS.sh is enabled, is there a way to use grep to take a section and output that onto the CLI that I'm looking at?

For example, I would like to find anything in sh run that matches the value switchport trunk, but instead of running sh run | i switchport trunk and outputting multiple lines of futile results, is there a grep command that takes the section of those results?

See below:

Using show run | include switchport trunk

 switchport trunk encapsulation dot1q
 switchport trunk encapsulation dot1q
 switchport trunk encapsulation dot1q
 switchport trunk encapsulation dot1q
 switchport trunk encapsulation dot1q

More of what im looking for with IOS.sh with grep

interface GigabitEthernet1/0/21
 switchport trunk encapsulation dot1q
 switchport mode trunk
!
interface GigabitEthernet1/0/22
 switchport trunk encapsulation dot1q
 switchport mode trunk
!
interface GigabitEthernet1/0/23
 switchport trunk encapsulation dot1q
 switchport mode trunk
  • 1
    As I understand, IOS.sh is supported by ISR and Catalyst after version 15.1 (4) M, 15.1 (2) S. – Roger Sanghee Gold May 14 '19 at 0:32
5

Cisco IOS Shell works on Cisco Routers and Switches.

The Cisco IOS Shell (IOS.sh) feature provides shell scripting capability to the Cisco IOS command-line-interface (CLI) environment. Cisco IOS.sh enhances the process of controlling and configuring an IOS router using the CLI by including, variable substitution, paths, conditional statements, loops, pipes, and so on to enhance the user experience of Cisco IOS CLI users.

First question: Is IOS.sh router or switch specific? Or are they able to be used for both types of devices as long as the firmware version is 15.1 or later?

Cisco IOS Shell was introduced with Cisco IOS Release 15.1(4)M, 15.1(2)S, and later releases for Routers. Cisco IOS.sh must be configured and enabled to use the Cisco IOS.sh features and functions on your router.

I cannot find any documentation explaining when it was introduced into IOS for switches.

Second Question: Now that IOS.sh is enabled, is there a way to use grep to take a section and output that onto the CLI that I'm looking at?

The IOS CLI has a facility to 'pipe' text from a command into a set of programs that can filter or redirect the output. The Cisco IOS.sh has expanded this facility to support more than one 'pipe' command on a line of input. The commands are executed concurrently, and print whatever the final command in the 'pipeline' prints.

Example

Router# show version | grep '^C'
Cisco IOS Software, 7200 Software (C7200-P-M), Experimental Version 12.2(20090611:002213)
Copyright (c) 1986-2010 by Cisco Systems, Inc.
Compiled Tue 16-Jun-10 14:23 by janedoe
Cisco 7204VXR (NPE225) processor (revision A) with 114688K/16384K bytes of memory.
Configuration register is 0x0

This example prints all lines that begin with uppercase C.

There's a similar method for the new IOS-XE that is running on Switches, for instance, the Cisco 3650, 3850, 9200, 9300, 9500 Series etc.

This method is called Guestshell, which is a virtualized Linux-based environment, designed to run custom Linux applications, including Python for automated control and management of Cisco devices. It also includes the automated provisioning (Day zero) of systems. This container shell provides a secure environment, decoupled from the host device, in which users can install scripts or software packages and run them.

The following example shows how to enable Guest Shell on a Catalyst 3850 Series Switch:

Device> enable
Device# guestshell enable 

Management Interface will be selected if configured
Please wait for completion
Guestshell enabled successfully

Device# guestshell run python

Python 2.7.11 (default, Feb 21 2017, 03:39:40) 
[GCC 5.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Device# guestshell run bash

[guestshell@guestshell ~]$

Device# guestshell disable 

Guestshell disabled successfully 

Device# guestshell destroy 

Guestshell destroyed successfully 

There's a complete guide on how to use Guestshell for IOS-XE here: https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/prog/configuration/166/b_166_programmability_cg/guest_shell.html

Please notice, you need to run version 16.6. at least.

Cisco IOS Shell whitepaper: https://www.cisco.com/c/en/us/td/docs/ios/netmgmt/configuration/guide/Convert/IOS_Shell/nm_ios_shell.pdf

Cisco IOS Shell complete command reference: https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/ios_shl/command/ios-shell-cr-book/ios-shell-cr-a1.html

  • 1
    Cisco IOS Shell only works on Cisco Routers. This is incorrect, I know for a fact (having used it in the past 72 hours) it is available on Catalyst 9300s, 3560Xs, and 2960s switches among other switch platforms. – YLearn May 14 '19 at 6:37
  • @YLearn And yet i cannot find any documentation for this, but as you have it hands-on, i'll, of course, edit the answer to reflect your observation. Thank you. – user56700 May 14 '19 at 6:42
  • Agreed. Consider though that the terminal settings you can adjust are poorly documented for most switch platforms (go ahead, check for terminal length in your favorite switch's command references). Doing a show terminal on the CLI will give you your best indication if the shell is present as there will be a line that reads Shell: disabled (by default, enabled if it has been enabled). – YLearn May 14 '19 at 7:06
  • @YLearn With all that knowledge you posses, maybe you should add an answer? :-) – user56700 May 14 '19 at 7:11
  • 1
    I don't have an actual answer to his second question, as I use it for other functionality. So rather than post my own, I figured I would help improve an existing answer. – YLearn May 14 '19 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.