It’s been way too long since my last blog post, so I figured I’d get one out! Join me on this quick little journey to learn more about the autocommand… uh… command.
What is it?
The autocommand is just as it sounds: it automatically runs a command at login time. It’s applied to the console, auxiliary, and VTY lines on your router or switch. Upon login of either a specific user or any user the autocommand feature will automatically execute a command and display the output, and then by default disconnect the user session.
Only one command can be issued by the autocommand feature. You can also avoid the automatic disconnect by issuing the autocommand-options nohangup command on the line.
Why use it?
Well there’s some great use cases for the autocommand. In a large enterprise environment with many different network admins and engineers you may want to know if anyone else is logged into the same device as you. You can quickly determine that using the who command. The output will tell you who is logged, the vty or console line they’re logged in on, and for how long they’ve been logged in.
Another use case is on a router you could automatically issue the show ip interface brief command and see which interfaces are up or down right away. This may aide in the troubleshooting process.
Maybe you want to see routing adjacencies as soon as you login to ensure the network is in good health. I’ll illustrate this using the show ip eigrp neighbors command and autocommand:
To configure the autocommand feature enter global configuration mode, go to the lines you want to add the autocommand to, and issue autocommand followed by the command you want to run at login. To disable the automatic disconnect issue the autocommand-options nohangup command on the line as well.
R1#config t Enter configuration commands, one per line. End with CNTL/Z. R1(config)#line vty 0 15 R1(config-line)#autocommand who R1(config-line)#autocommand-options nohangup R1(config-line)#
The autocommand is an extremely useful feature for any environment. It can easily save you a step and inform you of some important information as soon as you login to your devices. Remember, these are exec level commands only, so only show or verification commands can be utilized with autocommand.
If you’re using autocommand shout out in the comments, or yell at me on Twitter, because I’d love to know how you’re using it in your network!