IOS shell processing, variables and router-ids

IOS shell processing, variables and router-ids

IOS 15.1(4)M brought some nice cool new stuff with it. With it was shell processing, which opens up a plethora of linux commands.

Enabling shell processing on Cisco IOS

To enable shell processing we use the command:
R17(config)#shell processing full
R17(config)#
This then allows us to use lot's of new commands. To see the new commands type in "man":
R17#man
((              evaluate a numeric test expression
IOS.sh          The IOS shell
[[              evaluate a logical test expression
cat             output data from a pipe or file to the terminal
compatibility   compatibility information on IOS.sh
control         control constructs in IOS.sh
cut             edit piped output
echo            echo arguments to the terminal
expressions     usage of expressions in IOS.sh
false           return false in while or if expressions, and set the result
fetch           return values from the configuration database
for             IOS.sh for loops
functions       IOS.sh function facility
grep            search for regular expressions in piped output or files
head            print the first lines in the input
if-else         IOS.sh if command
interface       print interfaces that match the argument
let             evaluate a numeric expression, and set the result
man             print information for builtins
more            page piped output to the terminal
nl              number the lines in the input
null            ignore the input
printf          output formatted data to the terminal
quoting         IOS.sh quoting facility
read            read input into variables
scripting       how to script the IOS CLI
set_oper        set operational values
sleep           pause execution of the terminal
sort            sort the input
tail            print the tail of the input
true            return true in while or if expressions, and set the result
uname           print system information
variables       usage of variables in IOS.sh
wc              count lines, words, and chars
while           iterate while an expression is TRUE

R17#

Using grep to limit output

Now that we have enabled shell processing, we can use "grep":
R17#sh run int lo0 | grep 'address'
 ip address 123.17.17.17 255.255.255.255

R17#
This gives us the ip address.

Using cut to get an IP address

We can then use "cut" to return just the numbers:
R17#sh run int lo0 | grep 'address' | cut -c 13-24
123.17.17.17

R17#
This can be useful, as we can turn this command into a variable.

Why would we do this? Well, for certain things, such as setting router-ids for routing protocols, we would usually hard-code this to be the loopback interface's IP address. When switching from one router to the next it's easy to forget what the IP address is. You can always use "do sh run int lo0", but then it's easy to lose the flow, having it set as a variable makes life much easier.

Creating a variable in IOS shell

To create a variable we use the command "variable=variableoutput":
R17#varMyLo0=`sh run int lo0 | grep 'address' | cut -c 13-24`
Here, we create a variable called "varMyLo0". The backticks set the output of the command as the actual variable (the IP address).

Using a variable to set a router-id

We can then use this variable when configuring the device:
R17(config)#router bgp 100
R17(config-router)#bgp router-id $varMyLo0
R17(config-router)#do sh run | sec bgp
router bgp 100
 bgp router-id 123.17.17.17
 bgp log-neighbor-changes
R17(config-router)#exit
If we do this again, just to prove it works, for OSPF, we can see that OSPF is not running, we can create the OSPF process, and, again, use the variable to set the router ID:
R17#sh run | sec router ospf
R17#conf t
R17(config)#router ospf 100
R17(config-router)#router-id $varMyLo0
R17(config-router)#end
R17#sh run | sec router ospf
router ospf 100
 router-id 123.17.17.17
R17#
So, now, you don't need to keep looking at the "sh run int lo0" to remind yourself of the IP address, and type it in manually, or copy and paste it.

If the IP address is shorter (say 123.1.1.1) then the cut would be shorter (cut -c 13-21).

This could save some time during the exam!

If you have any good shell processing tips, then feel free to comment with them!

CCDP passed, normal studies can now resume

I just sat and passed the CCDP exam.



Spending nearly a day and half flying to, around, and from the USA over the last two weeks gave me a lot of time to read the certification guide, as well as the other one I mentioned, after I passed the CCDA.

I would highly recommend both books. Especially the official guide.


I havn't finished all of the official guide, but I will continue reading it, as it is a very good book. Not just for the exam, but it's one of those books that every network engineer should read to understand more about how to properly design a network. I would give it a full five out of five stars. Well recommended!

The exam itself was pretty easy (thanks to the guide), a bit of routing protocol knowledge really does help, but I was done in about ten minutes. 55 questions, no drag and drops. Walked out feeling good.

So now it's back to CCIE.
104 days to go.

Time will fly.

I must say that I don't really feel prepared at the moment. I do know my stuff, I feel confident that given unlimited time to sit the exam I would pass with full marks. Unlimited time, however, is not an option.

So, how best to prepare? How best to makes sure I can do what's requested in the limited amount of time?

My wife is very understanding, thankfully, and she knows that I need more time to study at the weekends. The flip-side of this is that I also want to spend time with my family. The boys are at a great age now of three and a bit, where they are fun to play with. So, really, I am not one of those people who can do 12 hours a day study, partly by choice, partly due to other commitments (and my family is far more important that a qualification, really).

So, although I can squeeze some more study time out, it's about working smarter, not harder.

Still trying to come up with a plan though!

If any of you have any ideas, then I'd really like to hear them!




Got bored. Got CCDA. CCDP next.

Studying for CCIE can get a little bit boring. It's a fairly constant rotation of reading, more reading, re-reading, labbing, bit more labbing, and then loads more labbing.

So, I decided to take a little side-road down this long path towards CCIE-dom, and get my CCDP. Because I don't have the CCIE yet (which would fulfil one of the prerequisites), I have got to do the CCDA first. FYI the prerequisites are a valid CCENT, CCNA Routing and Switching, or any CCIE.

So I did it.

Arrived about half an hour early, did all the paper work and pictures, triple signatures, sat the exam, and passed.


I really do not think that it is a hard exam - certainly not when I am in the midst of CCIE-study. There are a number of questions about routing protocol specifics, which are very easy, many of the questions just need a bit of logic to get through them, the rest were all answered by reading the study guide.

The study guide is very well written, it's clear and concise and I finished it within a week.


You can grab it from Amazon by clicking the picture above.
So now I have this, I can sit the CCDP exam, which should be a little bit more fun.

By the way, when did Associate level exams cost the same as Professional level? The CCDA exam cost £151 as does the CCDP. It was £135 for a CCNP exam back in 2012. CCNA was £123 in 2009, are all associate and professional exams the same cost now?

Anyway, I am off on a tour of the US offices for a few days, so lot's of time in planes and airports, armed with my Kindle. I have already started reading the "simplified guide", which is pretty good so far. I wouldn't say it's got all the depth I will probably need for the CCDP exam, but its a good place to start.


I also have the Cisco CCDP guide:


I have been skimming through this at work, and again it's very good. I should be able to finish the the simplified guide on my first flight (London to Philadelphia), and then get through the official one when going from Philly to Arizona, and then from Arizona to Boston. If that's not enough time then I can finish it on the flight back to the UK (though that's a over-night flight, so I might sleep instead).

Anyway, plenty of time to get up to scratch for the CCDP exam at the end of this month, before it's back to the CCIE studies. Then it'll be three months of labbing before the CCIE lab exam in July.

I really should start packing for my trip now. Have a good weekend all.