Linux scripts on Cisco IOS?


– This is a continuation
of a series of videos where I’m teaching you to become a better network engineer. And teaching you commands in the Cisco IOS that you
may not have known about. (upbeat music) Please do me a favor. Put a comment below this video and let me know when
you’ve learned something. So put a time stamp on the video. So how far did you get through the video before you learned something? Which command did you learn? If you know commands that I haven’t used options that I haven’t used please add them below this video. So that we can all learn from one another. I wish I knew everything, but I don’t. I’m just sharing some tips and tricks that I know, but please also add your tips and tricks below this video. Because this is YouTube please, would you subscribe to my YouTube Channel? Please, would you like this video? If you find it useful. And please click on the
bell to get notifications when I post a new video. In this video I’m going to show you some Linux commands you can run on Cisco IOS that will hopefully save you a lot of time. And hopefully surprise
you with what’s possible on the Cisco IOS. In this example I’m
running a Cisco router. This is a traditional Cisco IOS. In other words, classic Cisco IOS Version 15.6(2)T This is a viral image that’s running with InGenius 3. So, on this router what I’m going to do is enable shell processing full. This allows me to run Linux commands directly on the Cisco IOS. I could also just do it this way. If I only want to run it
for my current terminal and not enable it globally on the router. Have a look at the series of videos if you are not sure about
what this command does. I’ve discussed it in previous videos so I won’t go through
all the options here. Now shell processing supports
quite a few commands. If I type show shell functions I can see that cat is
supported as an example. Grep is supported. But not this option interface. Print interfaces that match the argument. I’m going to run a very basic scripture. Which is for X-X in
interface Ethernet zero do echo done This is a very basic script. Paste that directly into privileged mode. Notice I see the interfaces on the router. Similar to show IP interface brief, but I’m only looking
at Ethernet interfaces. So again, that’s the script that I ran. I’ll post all these
scripts below this video. So don’t worry trying to copy this down. Just get it from below this video. That’s showing me the
interfaces on the router. Now that may not be that interesting. So let’s expand the script. I’m going to say for X-X
in interface Ethernet do echo. Echo is one of the shell
functions available. Notice over there. Echo arguments to the terminal. So I’m going to basically echo something to the terminal. Based on show interface
include input errors. So this is going to show me not just the interfaces, but it’s also going to show me any input errors. So this line input errors
CRC frame overrun ignored is displayed in the output. So you may prefer doing that on a switch. See, here’s my switch. Terminal shell to enable the shell. Paste that in. I see all the interfaces on the switch. And now I can see input
errors CRC overruns, etc. I’ll be able to see any errors on an interface by simply running a very basic two line script if you like. If you want more details this is available in the Cisco IOS Shell
Configuration Guide. Again I’ve covered some
of this in separate videos where I’ve talked terminal shell versus enabling this globally on a device. But if you scroll down, they start talking about scripts that you can run. So very basic script is
echo here is a string with X-Y-Z in it where
X-Y-Z is a variable. In my basic script this is my variable, X-X. So that’s used in multiple places. Scrolling down a bit further we can use if statements. We can use for loops. So let’s take a very basic for loop here. Directly from the documentation. On my switch, I’ll paste that in. For X in one two three four five echo X so just print that out. That’s what we get. One, two, three, four, five. Not very interesting,
but let’s do something with this by using a loop with a break statement. So I’ll copy this exactly as it is. And I’ll paste that in to switch. And we get numbers one,
two, three, up to ten. Again, not that interesting. But what I’ve done is I’ve taken this exact script and then I’ve enhanced it slightly to do something useful. So, here’s my script. I’ve created a function which means that it’s a command that I
can run multiple times. Rather than just pasting
something into the C-L-I. So at the moment on the switch if I type shirun, that doesn’t work. It’s actually trying to do a
domain lookup here on that. I’ll speed up the video to break that. Notice that it’s translating shirun. So config no IP domain lookup. If I type shirun, that
command doesn’t work. It’s trying to do domain lookup on that. Obviously, shirun like
that will do something so show space run, but S-H-R-U-N is not a valid command. But what I can do is paste my script in. So I’ve created this
function called show run. Literally pasting that
scripting that I’ve created. Now if I type show run it’s doing a whole bunch of stuff. Actually, let me edit that down. What I’ve done here is
create this function setting N to minus one and while something is true, do something. N is equal to itself plus one so while N is less than or equal to three type show run interface
gigabyte zero something. I get rid of this show IP route because that just confuses the output. Paste that back in again. Show run. What this command has done is it’s running a show run interface on specific interfaces. Notice gigabyte is zero zero. Gigabyte zero one. Gigabyte zero two. And gigabyte zero three. It’s also printing out this number which came from our script that echo. Let’s get rid of that. So I’m basically creating a function here that does a show run of interfaces on this switch. So show run first interface zero zero. And then zero one, zero two, zero three and so forth. So it’s doing a show
run on each interface. But you could type any command here. I’ve just done show run interface gigabyte zero and then a number. I could do show interface like that. So rather than show
run, do a show interface on individual interfaces. So type that again. Show run. There’s the first interface. There’s the second interface. Third interface. Fourth interface. And done. Now there are more interfaces than that on this switch. A whole bunch of interfaces
are available on this switch. But what I wanted to show you is that you can run Linux scripts directly on the Cicso IOS by simply enabling shell processing full either globally on the switch or just typing terminal shell. This document on Cisco’s website which I’ll link below, gives you more examples were you can do logical tests. If this equals this than echo something. There’s a whole bunch of
options that you can do. This is actually one of the commands I’ve just shown you. You can actually configure interfaces if you want to. Says an example set to the interface description to something. Okay, I don’t want to turn this into a programming video because
that will get too long. I just wanted to show
you some basic scripts that you may find useful. Like this showing all interface errors. And then you can do basic
or more complex scripting. Okay so I hope you
found this video useful. I hope you’ve learned something. I’ll continue creating additional videos showing you options in the Cisco IOS that perhaps you don’t know
about that can make you a better network engineer. Once again, if you don’t
mind please subscribe to my YouTube Channel. Please like this video and
please click on the bell to get notifications. I’m David Bombal. I want to wish you all the very best. (upbeat music)

Leave a Reply

Your email address will not be published. Required fields are marked *