The simplest way to repeatedly run a Junos CLI command is to pipe the command to ‘refresh’. This will automatically repeat the command you have entered at the specified interval. It also prints a handy timestamp so you know exactly when the command was run.
This works well in situations where you need to watch some sort of incrementing counter. Whether that is during your own troubleshooting activities or when JTAC asks you to run the same command repeatedly.
Note that this is different from repeating a previous command just once. For that, you can go through your command history using the up and down arrows, or ctrl-p and ctrl-n.
The below examples were run on a vQFX, but the refresh command should be available on any Junos device.
Here’s an example of refreshing show chassis alarms every 10 seconds. To stop the output use Ctrl-C.
{master:0}
lab@vqfx-1> show system alarms | refresh 10
---(refreshed at 2023-11-21 06:14:02 UTC)---
No alarms currently active
---(refreshed at 2023-11-21 06:14:12 UTC)---
No alarms currently active
---(refreshed at 2023-11-21 06:14:22 UTC)---
No alarms currently active
---(refreshed at 2023-11-21 06:14:32 UTC)---
No alarms currently active
---(*more 100%)---[abort]
{master:0}
lab@vqfx-1>
This can combined with other pipe commands to limit output down to just what you want to see.
In this case, we’ll look at the output rate of a particular interface.
{master:0}
lab@vqfx-1> show interfaces xe-0/0/10 | match "Output rate" | refresh 10
---(refreshed at 2023-11-21 06:18:54 UTC)---
Output rate : 1621688 bps (0 pps)
---(refreshed at 2023-11-21 06:19:04 UTC)---
Output rate : 1565656 bps (0 pps)
---(refreshed at 2023-11-21 06:19:14 UTC)---
Output rate : 1679168 bps (0 pps)
---(refreshed at 2023-11-21 06:19:25 UTC)---
Output rate : 1664392 bps (0 pps)
---(*more 100%)---[abort]
{master:0}
lab@vqfx-1>
Another example is if you want to see the output rate for all xe interfaces, you can use the following. This shows all xe interfaces, matches only the lines that have “Physical interface” or “Output rate” and then runs that whole command every 20 seconds.
The reason to match both of these is to get the name of the interface the output rate is from. Otherwise, you end up with just a list of output rates and it may not be clear what interface they come from.
{master:0}
lab@vqfx-1> show interfaces xe-*| match "(Physical interface|Output rate)" | refresh 20
---(refreshed at 2023-11-21 06:31:06 UTC)---
Physical interface: xe-0/0/0, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/1, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/2, Enabled, Physical link is Up
Output rate : 794120 bps (0 pps)
Physical interface: xe-0/0/3, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/4, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/5, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/6, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/7, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/8, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/9, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/10, Enabled, Physical link is Up
Output rate : 1585504 bps (0 pps)
---(refreshed at 2023-11-21 06:31:26 UTC)---
Physical interface: xe-0/0/0, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/1, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/2, Enabled, Physical link is Up
Output rate : 837360 bps (0 pps)
Physical interface: xe-0/0/3, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/4, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/5, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/6, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/7, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/8, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/9, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/10, Enabled, Physical link is Up
Output rate : 1619656 bps (0 pps)
---(refreshed at 2023-11-21 06:31:46 UTC)---
Physical interface: xe-0/0/0, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/1, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/2, Enabled, Physical link is Up
Output rate : 815544 bps (0 pps)
Physical interface: xe-0/0/3, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/4, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/5, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/6, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/7, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/8, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/9, Enabled, Physical link is Up
Output rate : 0 bps (0 pps)
Physical interface: xe-0/0/10, Enabled, Physical link is Up
Output rate : 1602872 bps (0 pps)
---(*more)---[abort]
{master:0}
lab@vqfx-1>
The benefit of using the refresh command is its simplicity and availability. You don’t need to script something up or use an external tool. It’s right there waiting for you to use it.
The main downside is that you don’t seem to be able to specify how many times it should repeat, only how often. Also, it only works with a single line command, you can’t specify several commands that you want repeated together. For example, where you want to gather counters from several different show commands.