Chapter 6. Op Scripts

Op and event scripts are powerful tools you can use to automate the operation of your router. Have you ever wished you had a way to script a CLI command on the router? Or that you could program your router to always run a particular CLI command when a particular event occurs? Op and event scripts can do these things and more.

In this chapter, we will focus on op scripts. However, much of this information will also help you work with event scripts, which we cover in Chapter 7.

Use Cases

Before diving into the way op scripts work, let’s take a moment to look at the big picture: what can you do with op and event scripts? To give you an idea, let’s look at some use cases.

Custom CLI Commands

Junos has a robust and useful CLI, with many, many commands to cover a variety of situations. Using the CLI, it is fairly easy to perform just about any action you desire. However, there are times when you could make things even easier if you were able to script command sequences.

Consider this example. Imagine your network has a monitoring system that reports when a BGP session goes down. Your standard response is to log in to the router, run show interfaces terse to find the interface that carries the session, and then run show interfaces extensive to look at the details for that interface.

You could simplify this process by simply being able to run a single command that automatically figures out which interface has the destination and then runs show interfaces extensive for that ...

Get Automating Junos Administration now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.