Expand all | Collapse all

Op script to display route information

Jump to Best Answer
  • 1.  Op script to display route information

    Posted 05-16-2018 03:59

    Hi all,

    I have an op script that I modified from a found script and I'm having trouble getting it to work properly. I need to perform a 'show route detail <ip>' and the script seems to run, but it doesn't take into account the 'ip' variable and shows everything. Here is the script:


    version 1.0;
    ns junos = "*/junos";
    ns xnm = "";
    ns jcs = "";
    import "../import/junos.xsl";
     * Shows the source router and AS path of an IP
    var $arguments = {
       <argument> {
          <name> "ip";
          <description> "IP address";
       param $ip;
       match / {
       <op-script-results> {
           var $rpc = {
              <get-route-information> {
           var $out = jcs:invoke($rpc);
           <rt junos:style="detail"> {
                 <output> 'Prefix                         Source Router                         AS Path';
                     for-each ($out/route-table/rt) {
                 <output> jcs:printf('%-25s %-25s %-s', rt-destination _ "/" _ rt-prefix-length, rt-entry/protocol-nh/to, rt-entry/as-path);

    The output formatting probably needs to be tweaked a bit, which I can do, but the command that is run is 'show route detail' with no IP qualifier. I don't mind at all trying to figure out the right syntax, but I am not sure where to look in the documentation. Or maybe I am doing this all wrong. Please let me know!



    EDIT: So I was kind of able to get just my requested line of output by changing the 'foreach' statement:


    for-each ($out/route-table/rt[rt-destination = $ip]) 

    I have two issues now - first is that the match has to be exact or the output shows nothing. The second is that I still don't think something is right, as this script running on a router with lots of routes doesn't complete. It works on my lab router fine, so I am clearly not structuring the command correctly or something.

  • 2.  RE: Op script to display route information
    Best Answer

    Posted 05-16-2018 05:03



    I thing the RPC that you are issuing should look like

           var $rpc = {
              <get-route-information> {
              <destination> $ip;

    Please check.

  • 3.  RE: Op script to display route information

    Posted 05-16-2018 05:11

    Thanks, that did it!