10

I know we can use auto-completion (tab key) and abbreviated commands (such as sh ip int bri) to speed up typing.

However, I'm still not satisfied with typing crypting chains such as sh ip dh sn bi | i 20.12 for show ip dhcp snooping binding | include 20.12.

Can I define shortcuts for often used command sequences, and how?

  • If you know what you're typing, you'll be thinking show ip dhcp snooping... when typing sh ip dh sn... If you're sending that to someone else in an e-mail, at least make the abbreviations obvious (e.g. snoop vs sn). I prefer to not abbreviate in this case. IMHO, aliases are great when engineers are deploying configs for non-cisco savvy techs that still need to see some useful output. Aliases for cisco-savvy people just make them lazy. (Again, totally just my opinion...) – Tarah May 26 '13 at 0:59
  • 1
    Learn to type faster is one option. ;-) – generalnetworkerror May 26 '13 at 3:19
  • 1
    @generalnetworkerror I frequently have to use saturated low-bandwidth satellite connections with 800 ms latency. Less keystrokes would be an option, typing faster not really (though I'm fast). – Stefan May 26 '13 at 8:28
  • Are you using the Nagle algorithm over that high-latency link? "Router(config)# service nagle" – generalnetworkerror May 26 '13 at 8:55
  • @generalnetworkerror Very good point! I don't use nagle, but everywhere a WAAS for TCP optimization and compression. – Stefan May 26 '13 at 13:30
17

We can use the alias command in global conf mode:

alias <mode> <command-alias> <original-command>

<mode> is one of the many IOS command modes. If you need it in different modes, you have to call it for each one - type alias ? to get a long list of modes.

An example for checking for a dhcp snooped IP, type in global conf mode

alias exec snoop show ip dhcp snooping binding | include

Now you can simply type snoop 172.16.20.12 to check for this IP or snoop 801 for checking all IPs in VLAN 801, for example. Do similarly for show mac-address-table | include and you're faster in searching and troubleshooting.

Further tipps:

  • document your aliases for you and for your collegues
  • sh aliases shows your aliases plus the predefined ones
  • while no alias <mode> <command> can be guessed for removing an alias, no alias <mode> deletes the aliases for a complete mode - so you can clear several at once, default alias <mode> works similarly, as expected
  • if you decide to use aliases, deploy them once everywhere you may need them
  • tools like Cisco Prime can help in deploying
  • don't forget the original commands ;-)
| improve this answer | |
  • Lol did you answer your own question in the same minute you posted it? :) Archiving knowledge? – Bulki Oct 10 '13 at 9:00
  • @Bulki Sharing knowledge, building meaningful site content during the beta phase, looking for alternative solutions. What does your "Lol" mean then? – Stefan Oct 10 '13 at 9:38
  • Well, I it's funny when you see that, but I do think it's important to do this indeed to have a good knowledge database for others as well :) I was suprised I even noticed it :) good posts btw! – Bulki Oct 10 '13 at 13:57
6

For complicated tasks, I suggest looking at TCL. You can use TCL to create scripts that can be stored and run on your IOS/Nexus devices providing an amazing amount of flexibility in collecting and displaying data.

While it isn't necessarily faster for simple tasks, you can collect and correlate information from multiple commands and reformat it as you like. It can also pull information from SNMP.

If you haven't looked into it, you can find one such document here.

Edit: I didn't add this, but probably should have. Once you have your TCL script in place, you can use the alias command from Stefan's great answer to create a faster access to the script. For example:

alias exec mac-lookup tclsh flash:mac-lookup.tcl
| improve this answer | |
  • Also a good suggestion, but doesn't answer the OP's question. :-) – John Jensen May 25 '13 at 18:29
  • While not a shortcut in the alias sense, it is a shortcut as it can do a number of things and display the data you want in less time than it takes to type all those commands. For instance, if you gave it a MAC address, you could get back the interface it was connected to, how many other devices were connected on that port, the interface counters of that interface, any DHCP snooping entries for that MAC, and so on. The options are as limitless as you want them to be with TCL. Aliases while great are limited in scope and how much work/typing they can save. – YLearn May 25 '13 at 18:43
  • I keyed in on the "often used command sequences" and "speed up CLI typing" parts of the Q. Since many common tasks require a sequence or series of commands to be run, TCL is better in these cases to provide a "shortcut." – YLearn May 25 '13 at 18:46
  • Agreed with @YLearn; sometimes a better (not necessarily the best) answer adds much value for the OP and others who read this to understand all the options to CLI enhancements. Novices OP's may not even be aware of TCL, but this may be exactly what they're seeking. – generalnetworkerror May 26 '13 at 3:26
  • My conter-argument is the amount of effort required in writing a Tcl script vs creating an alias, and not everyone has the free time (or desire) to learn Tcl syntax. Re: answering the OP's question, I can see the usefulness of pointing out the Tcl option. – John Jensen May 26 '13 at 3:31
2

Personally I think alias' are a bad idea. You never know when you're going to be logging onto a device that doesn't have your favourite alias defined. Then you need to remember what you type form the start again.

The best thing to do? Just keep typing it out. Eventually your typing speed will improve.

| improve this answer | |
  • I have no problem using aliases. My rule of thumb is that they should be used to make work more efficient, not to simplify things I don't know/understand. If you can do it without the alias, great, if not make sure you understand what the alias does. – YLearn May 26 '13 at 20:37
1

If you use securecrt (and if you dont want to get into too much shell scripting) for your telnet/ssh/console access you can always "record" your commands, it has an option and then you can simply select your recorded script in tools I believe it is

| improve this answer | |
0

Depending on what you do a better option may be to write shell, expect, or other scripts to do your common tasks.

For basic troubleshooting it's even nicer to have my alerting system already perform the info-gathering part.

Combining tools like notch, with related tools like its "Mr CLI" can let you create some really powerful tools very easily, giving you a hand today, and an easy route to further improve things tomorrow, if not by fully automating you might be able to shift the tasks onto a helpdesk who can be given a trivial web-app which does the basic steps and helps fix user problems faster.

| improve this answer | |
  • While all of this is basically spot on, it still doesn't answer the OP's question; it's basically creating points for discussion, which we should be avoiding. – John Jensen May 25 '13 at 18:24

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.