Junos OS

 View Only
last person joined: 9 hours ago 

Ask questions and share experiences about Junos OS.
  • 1.  op script example

    Posted 11-10-2007 06:00
    Hi,

    I need example of JUNOScript like cisco's alias, I use this one:
    alias exec wrn copy system:/running-config tftp://xxx.xxx.xxx.xxx/router-confg
    for "fast" copy config file to tftp server.

    So for Juniper I need 'op wrn' for this:
    file copy /config/juniper.conf.gz ftp://username:password@xxx.xxx.xxx.xxx/router-confg.gz


    TIA!

    ---
    Yev.
    #alias
    #junoscript


  • 2.  RE: op script example
    Best Answer

    Posted 06-26-2008 16:37

    It's very simple. You just need to file-copy command and source/destnation url:

     

    Here's an op script:

     

    jnpr@RE0# show system
    scripts {
        op {
            traceoptions {
                file filename;
                flag all;
            }
            file wrn.xsl;
        }
    }


    [edit]
    jnpr@# run op wrn   

     

     On my server:

     

     > ls *router*
      router-config.gz
    >

     

     

     

     

    <?xml version="1.0" standalone="yes"?>

    <xsl:stylesheet version="1.0"

        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

        xmlns:junos="http://xml.juniper.net/junos/*/junos"

        xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm"

        xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0">



        <xsl:import href="../import/junos.xsl"/>





        <xsl:template match="/">
            <op-script-results>
            <xsl:variable name="rpc">
               <file-copy>
                    <source>/config/juniper.conf.gz</source>
                    <destination>ftp://username:password@x.x.x.x/router-config.gz</destination>
               </file-copy>
            </xsl:variable>
              <xsl:variable name="result" select="jcs:invoke($rpc)"/>
            </op-script-results>
         </xsl:template >

    </xsl:stylesheet>


    #junoscript
    #Op
    #script


  • 3.  RE: op script example

    Posted 07-21-2008 05:21

    Arborist,

    thanks! Thats what I need!


    Is it possible to add in this script some informational output like this:
     ftp://usernameSmiley Tongueassword@x.x.x.x/router-config.gz 100% of   44 kB 2318 kBps

    ---
    Yev.



  • 4.  RE: op script example

    Posted 07-30-2008 00:05

    Arborist,

     

    pelase answer to me.

    I need this extra output for understanding is my ftp transfer good or bad.

     

     

    Thanks in advance!



  • 5.  RE: op script example

    Posted 09-04-2008 13:38

    Sorry for the delay.

     

    There is extra output for failure, but not for success. So you'll have to put in a conditional statement. The choose command will test if there is any contents (reply message) from the executed vairable "result".

     

        <xsl:template match="/">
            <op-script-results>
            <xsl:variable name="rpc">
               <file-copy>
                    <source>/config/juniper.conf.gz</source>
                    <destination>ftp://username:password@x.x.x.x/router-config.gz</destination>
               </file-copy>
            </xsl:variable>
              <xsl:variable name="result" select="jcs:invoke($rpc)"/>

            <output>
            <xsl:choose>                    
            <xsl:when test="$result/message">
          <xsl:value-of select="$result/message"/>
            </xsl:when>
            <xsl:otherwise>FTP'd Successfully</xsl:otherwise>
            </xsl:choose>
            </output>

            </op-script-results>
         </xsl:template >

     

    A true condition will reply with a message, in this case any ftp failures. 

     

    Here I put in an incorrect login. 

     
    jnpr@router# run op wrn    
    fetch: ftp://username:*@x.x.x.x/router-config.gz: Not logged in


    Here I disconnected interface from the network

     

    jnpr@router# run op wrn    
    fetch: ftp://username:*@x.x.x.x/router-config.gz: No route to host

     

     A false condition means there is no content reply from the executed variable. Which means FTP succeeded. Therefore I created test to reflect that:

     
    jnpr@router# run op wrn   
    FTP'd Successfully