- It's my aim to make you the best network engineer that you can be. In this video, I'm gonna show you three ways to run
scripts on Cisco devices. In other words, run them on box. You don't need Python to
run these scripting options. They'd been around in the
Cisco IOS for many, many years. I'm gonna show you how to
use TCL, or T-C-L scripts. I'm gonna show you how to use
the Embedded Event Manager. And I'm gonna show you how
to use the Linux scripts directly on Cisco devices. Again, you don't need
Python to run these scripts, you don't need a separate
VM or a separate shell. You can run these directly on Cisco IOS. So, in the same place you
type "conf t" or enable you'll be able to run these scripts. (theme music) - I want you to be the best network engineer in your organization. I want you to go to interviews and blow away people with
your knowledge and skills. When a senior network engineer
looks at what you're doing, surprise them with the
knowledge that you have. Now, a favor from you. If you enjoy this video, please like it and please subscribe
to my YouTube channel. If you enjoy these videos, click on the bell to get notifications when I post a new video. Now, with that being said, let me show you how you can do really cool
things on Cisco IOS devices. In this example, I'm using GNS3. I'm not using a special
version of Cisco IOS. I'm just using traditional
Cisco IOS devices here. Okay, so the first scripting
option is using TCL, or T-C-L scripts. This document was updated in 2011. In other words, this has
been around for a long time. The next one is the IOS
Embedded Event Manager. This has also been around for a long time. And then I'm gonna show
you the Cisco IOS Shell. I've shown you this in other videos, but here I wanna show you
some scripting options using the Cisco IOS shell. Okay, so let's start with TCL, or T-C-L. Now, you're gonna run this in enable mode on a Cisco device. In my junior 3 topology, here's Router 1. I've got Router 2, Router 3. These are all Cisco IOS, V devices. So, if I type short-version
here, notice VIOS. This is the version of IOS. There's nothing special about this. This is just standard Cisco IOS. Okay, so, T-C-L-S-H. Notice the mode that we're in. Whole bunch of commands
are available here. But what we're gonna do is we're
going to create a for loop. So, for each, and you can call
this anything, IP address, a variable, whatever you like. Notice the brackets. So for each value, here we are going to ping the variable, IP address. So, I'm gonna copy that
onto the Cisco device. I don't need to be in this
mode, so I'm gonna say, "TCL quit," to quit out of TCL, or T-C-L and I'm gonna paste this in. Notice what happens
when I press enter now. The router pings those 4 IP addresses, in the list. Now, this is a very basic script. I mean, what I could do here is add a whole bunch of
additional IP addresses, but what I'll do is I'll simply add back duplicates of
some of the IP addresses. So, I'll copy that, quit outta here, and paste that in. And that went very quickly, but notice, there I've pasted the script in, and what it's doing now is it's pinging every one
of those IP addresses, as well as the additional IP
addresses that I've specified. So, let's do T-C-L quit there. That's okay, but you don't necessarily wanna paste that in every time. But if you're doing some work on a device and you wanna test IP
connectivity to multiple devices, you can do that. A lot of CCI candidates use
this for testing connectivity in the CCIE labs. Now, what I've also got
here is a Windows PC. This is the Windows 10 computer and I'm running the Solarwinds
TFTP server on this computer. You can download the Solarwinds
TFTP server for free, using the link below. It's free software that
you can download and use. And what I've got here in
the TFTP root directory is a TCL script. Okay, so here's our script. I'll make the font a bit
bigger so it's easier to read. But, essentially it's the
same option as we had before. I've just got tab between
all the IP addresses. So basically, the same type of
script, but what I can do now is copy that to the flash of the router. So, what's the IP address of this PC? It's 10.1.1.101. The name of the file is
"ping.tcl" or ping dot T-C-L. It's up to you which way
you wanna pronounce that. So, back on my router, dir shows us that that file
doesn't exist in flash. Let's make sure that we
can ping the TFTP server. I can, so, copy TFTP flash. 10.1.1.101 is the TFTP server IP address. "ping.tcl" or ping dot
T-C-L is the file name. I'm gonna copy that to flash. That's now copied across. It is copied successfully. Dir shows us that that file is in flash. What you can do now is
simply use this command. So, "tclsh" and the name
of your script in flash. So, on my router, "tclsh" You may wanna do it this way. (typing) And notice that you go. Or just do "tclsh" and the
name of the file in flash and there you go, once again. So, you could put a file like
this in a flash of a device, you can actually call it directly from a TFTP server, if you want to. You don't have to run it in flash, but I did in this example, and notice that script
now pings all the devices. I could use more to look at my script. So, notice, there's
the script, once again. All it's doing is running
"tclsh" for each IP address in this list here. Notice the brackets once again. It's gonna ping the IP
addresses in that list. Okay, so that's a very basic
example of TCL or T-C-L. If you wanna get more information, have a look at this configuration guide. I've put a link below this
video if you wanna have a look at this and get more information. You can do various things with this, but I think the most useful, basic option, so the low-hanging
fruit, as they would say, is to simply use it to ping multiple devices in your network. Very basic script. Okay so that's T-C-L, or TCL. The next one is the Cisco
IOS Embedded Event Manager. Let's have a look at that. Once again, there's a lot of documentation on Cisco's website. They've got links for real-time
network event detection and more writing policy
using command-line interface, et cetera, but I'm gonna show you a fairly simple example
to get you started. What I've got here is a script that says,
"Event manager applet". Give it a name, so in this
example I'm looking for interface gigabit 0, 0 going down. Basically, what it's doing is that it's looking for this statement in syslog. So, it's looking for a
syslog message like that. As an example, on my router, if I go on to interface gigabit 0 0 and I shut that interface, notice, we'll see that statement in the output. Right over there. Interface has gone down. Now you can look for different events. So, always OSPF neighbor
relationship going down, or something else happening. You could use this to send you an e-mail if something happens in your network. I'm starting with a basic example here. Let me know if you're interested in more detailed or more complex examples. But basically, what we're
gonna do is look for an event and then, we've got a time
period, and different actions: action 1, 2, 3, 4, 5, and 6. And what we're gonna
do is run cli commands. Don't forget to use enable
as your first command, then conf-t, then we're gonna
go on to that interface, gigabit 0/0, and then
we're going to shut it down and no shut it, and then we're gonna write
a syslog message saying, "Interface went down." You can put any kind of message
there that you wanted to. But let's copy that. And again, I'll put the
script below the video so that you can copy it and use it yourself. You use all of these at your
own risk, but I've tested this, and I'll show you right
now that it does work. So, I'm going to global configuration mode and I'll paste that scripting. So, notice, in global config mode, event manager applet interface goes down. Now, notice what happens. Interface gigabit 0 0,
I'm gonna shut it down. So, interface has gone
down, but notice suddenly, interface has come up again. Notice the special message here: "Gigabit 0 0 went down." And if I type "do show
IP interface brief," notice, interface is up up. So, show run, let's have a look at that running config. Right at the bottom here,
notice, here's my event manager. I could change that as
an example, I could say, "What's going on? Gigabit 0 0 went down." Well, let's do that. Copy that in, so global config mode. Question mark will give you problems, so let's do that manually, and
I'll show you another trick, when it comes to question marks. So, let's do this, paste that in, press control v question mark. Now, I can actually add a question mark. So, on Cisco IOS, if you need to add a
question mark somewhere, use control v, to allow you to edit. So paste the rest of that there. And I should be in the right mode. So event manager is my mode. Let's paste that back. It's accepted that. And all I need to do, is end my script. Okay, so show IP interface brief. Interface is currently up up, but I'll go onto the
interface, and shut it. So I've manually shut the interface down. Notice we see our message: "What's going on? Interface went down." Notice, interface goes down,
but interface comes up again. So, interface has come up. Do show IP interface brief. Interface is back to being up up. Okay, we've also got debugs,
so before I wrap this up, let's have a look at debugs. So, what I'll do is enable that debugging, so EEM debugging is on. Go onto the interface, and shut it. And, hopefully what we'll see
now is the commands will run. And there you go. Okay so going up. A lot of output here,
let's make that bigger. Here, I shut the interface down. Notice the interface changed
state to administratively down. CLI open was called, so
the script was called. Some of the information is displayed because we've opened up a TTY line, or a connection to the device. You see this when you tell it
of SSH-2 a Cisco IOSv device. But notice, the important part is here. Out, router 1. We sync the command enable. Out, router 1, privilege mode. We've sent the command, config terminal. This is what displayed down. In global config mode. We synced the command,
interface gigabit 0 0. That's the mode. We've shut the interface down,
we've no-shut the interface, we've displayed a message,
and the script has now ended. And now, the interface has come up again, so show IP interface brief. Notice the interface is up up. So, basic example of a
event manager applet. Showed you that with the debug. So, that was a very basic
example of using the Cisco IOS Embedded Event Manager. I just wanted to get you started. You can have a look at this
document for more information. There's plenty of options. You could look for OSPF neighbor
relationships going down, and then you can get it
to send you an email, as an example if you want to do that. Lotta options available here, but that's a good one to get you started. Okay, the next one is the Cisco IOS shell. This allows you to use Linux commands directly on the Cisco IOS. Here's a very basic one. For x in 1, 2, 3, do something. What are we gonna do? We're gonna ping this variable, x, which would be 1, 2, or, 3
and then the script is done. So, let's try that on router 1. Here's router 1 again. For this to work, I have to
enable shell processing full, so either globally on the router switch, or I can do it on a per session
basis by using that command. So, you don't need to do both. This will just enable
it on the local telnet, or SSH, or console line
until you're finished, in other words, till you exit out, and then it'll stop running. This enables the function all the time. So, basically this enables Linux commands on the router switch. So, for x in 1, 2, 3, what are we gonna do? We're gonna ping 10 1 1 x, done. And notice, it now pings
those IP addresses. So, it pinged 10 1 1
1, it pinged 10 1 1 2, timed up there because
abort, and pinged 10 1 1 3. So, we've now pinged three IP addresses. Now, at the moment, show shell functions shows us that there are
no user-defined functions. We've only got built-in functions. So, built-in functions are what's enabled when you type that command. Terminal shell is an example. So, we can do things such
as shell run grep face. In other words, you use
Linux commands directly on the Cisco IOS. What we can do is create our
own user-defined functions. So, what I'm gonna do
is paste that scripting. Basically, we've created a
function, called "testping." Now, if I remove that
just to show you this, I'm gonna remove that function, and now when I try and use
the command "testping," it doesn't work. The command doesn't work. But when I paste that in now, and I use the command
"testping," notice it works, because I've created this
user-defined function. Notice the brackets, this is a function. And, what we're doing here
is running four commands, so, like pinging different devices. I could do something like, function echo, if you like. So, just get it to echo something. This is not doing much, except
printing stuff to the screen, but the point is that you can
create your own functions, that can do things. So, notice now, when I type "testecho," it just echoes those values back. It doesn't really do anything. "testping" is probably
more valuable to us. So, show shell function, now, shows us that we've got
these user-defined functions. Notice function test
echo, function test ping. Okay, so I think that's enough. This video is getting really long, but that gives you an
idea of what's possible, using the Cisco IOS. Remember, we didn't
have to run Python here. We didn't have to drop
down to a Linux shell. We didn't have to use a Linux VM. We ran these commands
directly on the Cisco IOS. Go out there, and show
people how much you know. Go and surprise them and
amaze them with your knowledge of the Cisco IOS. I'm gonna continue in the series, teaching you options
that not everyone knows, so that you can be a so-called
boss on the Cisco IOS, or like a really cool network engineer. Now please, if you've enjoyed this video, please like it and please
subscribe to my YouTube channel, click on the bell to get notifications so that you know when
I upload a new video. I'm David Bombal, I wanna
wish you all the very best. (theme music)