Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Robert_Decker1
Participant

How to get virtual system/router dynamic routes using the Run-Script API command

Hey,

Is there a way to get the dynamic/static routes from VSX virtual systems (VS/VR) using the Run-Script API command?

Meaning, build a script body composed of several CLI commands, such as:

vsenv <vsid>

show route

 

Thanks in advance.

0 Kudos
7 Replies
Bob_Zimmerman
Advisor

Try building a one-liner like this:

sh -c 'command 1;command 2;third "command with quotes";fourth \'command with ticks\';command 5'

I haven't used this construct with Run-Script before, but I use it with xargs all the time.

0 Kudos
Robert_Decker1
Participant

Thanks Bob.

My problem is that I've to run that commands in CLISH mode.

Is there a way to change the CLI mode using run-script API command?

For example:  >>clish;set virtual-system 4;show route;

I've also tried: clish -c 'set virtual-system 4;show route;' with no success - run-script failed

0 Kudos
Bob_Zimmerman
Advisor

Yeah, that's a limitation of clish. It's pretty solidly useless for troubleshooting or most automation. The best workaround I've found so far would be something like this:

 

sh -c 'printf "set virtual-system 4\nshow route\nexit\n" | clish'

 

That way, you can wrap the pipeline, do other commands to process the data locally on the firewall, then you get the eventual result back at the management.

There is also now the GAiA API which might be able to do what you want without involving clish.

0 Kudos
Petr_Hantak
Advisor

Probably this won't be perfect for you because you mention of use clish only. But in case you have an expert level access, then you can use following:

for i in /proc/vrf/*; do i=${i#*vrf/}; vsenv $i; echo "set virtual-system" $i > /tmp/clishcmd; echo "show route" >> /tmp/clishcmd; clish -i -f /tmp/clishcmd; done

 

Just change show route for any other command which you need.

0 Kudos
Robert_Decker1
Participant

Thank you Petr,

I've tried that in expert mode but it didn't work correctly.

It requires CLISH mode to respond with the correct results (for the combination of "set virtual-system ID" and "show route").

0 Kudos
Kaspars_Zibarts
Authority
Authority

can't you create shell script and then add custom clish command?

Usage: add command <command name> path <command path> description <command description>

we use those for "special" users that can execute only one command in clish that's script based

essentially you map clish command to a shell script

Robert_Decker1
Participant

Hey, I cannot, it's customer's device and we are not allowed to upload bash scripts there.

0 Kudos