Automation

 View Only
last person joined: yesterday 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  op script - Is there a way to break at page with "more" being shown

    Posted 04-16-2024 14:39

    Hello all,

    I wrote an op script that basically show a list of all the interfaces with information. Right now, if I run the script against a stack of 5 "48 ports" switch, I get basically 250 lines non-stop.   Is there a way to make the script stop every so many lines like a regular command would do?

    I am using

    <output> jcs:printf(""); 

    to display my  results.

    Thanks for your help.



    ------------------------------
    YVON LEDUC
    ------------------------------


  • 2.  RE: op script - Is there a way to break at page with "more" being shown

     
    Posted 04-17-2024 14:10
    Edited by asharp 04-17-2024 16:45

    I've never had any issue with "---(more)---" being displayed for op scripts.  Although, I don't usually print to screen using <output> jcs:printf("");

    My approach has always been to declare <output> just once, e.g.

    main <op-script-results> {
        <output> {
            /* print stuff here */
        }
    }
    

    Then depending on what I need to print, I would mostly just use: expr, uexpr or jcs:printf as required.

    Of course, also make sure that screen-length is recognised in your terminal.

    e.g.

    > show cli
    CLI complete-on-space set to on
    CLI idle-timeout disabled
    CLI restart-on-upgrade set to on
    CLI screen-length set to 62
    CLI screen-width set to 187
    CLI terminal is 'xterm-256color'
    CLI is operating in enhanced mode
    CLI timestamp disabled
    
    > set cli screen-length 80
    Screen length set to 80

    Regards



  • 3.  RE: op script - Is there a way to break at page with "more" being shown

    Posted 04-17-2024 17:05
    Edited by YVON LEDUC 04-17-2024 17:11

    hello Andy, 

    In your comment you mentioned 

    "I've never had any issue with "---(more)---" being displayed for op scripts. " 

    does you mean the result that your script generate don't stop until everything is shown? I was hoping to find a way to show my list in such a way that I would see a "---(more)---" every so many lines. 

    I modified my script to only have one set of <output> but it is still showing something like 250 rows in one shot. 

    also, my cli screen-length is set. 

    Regards. 



    ------------------------------
    YVON LEDUC
    ------------------------------



  • 4.  RE: op script - Is there a way to break at page with "more" being shown

     
    Posted 04-18-2024 04:17
    Edited by asharp 04-18-2024 04:25

    I mean to say that my script does display ---more---

    asharp@SRX-Node0> file show /var/db/scripts/op/mytest.slax
    version 1.0;
    
    ns junos = "http://xml.juniper.net/junos/*/junos";
    ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
    ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
    
    import "../import/junos.xsl";
    match / {
      <op-script-results> {
        <output> {
          var $rpc = <get-interface-information>;
          var $conn = jcs:open();
          var $results = jcs:execute($conn, $rpc);
          for-each ($results/physical-interface) {
            expr "Interface Name " _ ./name _ "\n";
          }
          expr jcs:close($conn);
        }
      }
    }
    
    asharp@SRX-Node0> set cli screen-length 20
    Screen length set to 20
    
    {secondary:node0}
    asharp@SRX-Node0> op mytest
    Interface Name ge-0/0/0
    Interface Name gr-0/0/0
    Interface Name ip-0/0/0
    Interface Name ge-0/0/1
    Interface Name fe-0/0/2
    Interface Name fe-0/0/3
    Interface Name fe-0/0/4
    Interface Name fe-0/0/5
    Interface Name fe-0/0/6
    Interface Name fe-0/0/7
    Interface Name ge-2/0/0
    Interface Name ge-2/0/1
    Interface Name fe-2/0/2
    Interface Name fe-2/0/3
    Interface Name fe-2/0/4
    Interface Name fe-2/0/5
    Interface Name fe-2/0/6
    Interface Name fe-2/0/7
    Interface Name fab0
    ---(more)---
    
    
    asharp@SRX-Node0> set cli screen-length 10
    Screen length set to 10
    
    {secondary:node0}
    asharp@SRX-Node0> op mytest
    Interface Name ge-0/0/0
    Interface Name gr-0/0/0
    Interface Name ip-0/0/0
    Interface Name ge-0/0/1
    Interface Name fe-0/0/2
    Interface Name fe-0/0/3
    Interface Name fe-0/0/4
    Interface Name fe-0/0/5
    Interface Name fe-0/0/6
    ---(more)---



    ------------------------------
    Andy Sharp
    ------------------------------



  • 5.  RE: op script - Is there a way to break at page with "more" being shown

    Posted 04-18-2024 09:11

    Thanks Andy. 

    Interesting.

    I ran the exact same code and on my switch, it just does not stop even after setting the screen lenght to 10.

    (Hostname: 2S-205-Lab_EX4300
    Model: ex4300-48p
    Junos: 21.4R3)



    ------------------------------
    YVON LEDUC
    ------------------------------



  • 6.  RE: op script - Is there a way to break at page with "more" being shown

     
    Posted 04-18-2024 11:22

    I was running my test initially on a SRX210 cluster running 12.1X46, which is the only physical hardware I had within reach on my desk.  I ran the same script on vMX and the behaviour was the same, in that the script displays ---(more)--- as I would expect that it would, and that vMX is running 22.1R1.10. 

    I wonder if it is something particular to the terminal s/w that you are using that is producing the behaviour that you are getting?  Do you see the same behaviour with a different terminal software?

    I've tried a few different terminal apps on MacOS and Win10 and all with the same behaviour (terminal, warp, iterm2, putty, openssh) , even tried using a console connection and again the same as well.  So unless it is something specific to that version of Junos (maybe??) I'm at a loss as to why you are not getting a ---(more)--- prompt by default



    ------------------------------
    Andy Sharp
    ------------------------------



  • 7.  RE: op script - Is there a way to break at page with "more" being shown

    Posted 04-18-2024 13:52

    Andy.

    I am running putty on Windows. if I run "sh interface terse", the display stops and --more-- is displayed. 

    I believe it might just be how the script is handled on EX switch vs the srx. I have opened a service call with Juniper and I'll see what comes up. In my code, I included a parameter for the stack member number so it limits the output for that member only which is more user friendly.

    I'll update is something comes up. 

    Thanks for your time.

    Thanks Andy for helping.



    ------------------------------
    YVON LEDUC
    ------------------------------