Junos
Reply
Regular Visitor
NikeBoy
Posts: 9
Registered: ‎11-10-2007
0
Accepted Solution

op script example

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:smileytongue:assword@xxx.xxx.xxx.xxx/router-confg.gz


TIA!

---
Yev.
---
Yev.
Juniper Employee
Arborist
Posts: 7
Registered: ‎06-24-2008
0

Re: op script example

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:smileytongue:assword@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>

Regular Visitor
NikeBoy
Posts: 9
Registered: ‎11-10-2007
0

Re: op script example

Arborist,

thanks! Thats what I need!


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

---
Yev.

---
Yev.
Regular Visitor
NikeBoy
Posts: 9
Registered: ‎11-10-2007
0

Re: op script example

Arborist,

 

pelase answer to me.

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

 

 

Thanks in advance!

---
Yev.
Juniper Employee
Arborist
Posts: 7
Registered: ‎06-24-2008
0

Re: op script example

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:smileytongue:assword@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:smileysurprised:therwise>FTP'd Successfully</xsl:smileysurprised:therwise>
        </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

 

 

 

Copyright© 1999-2013 Juniper Networks, Inc. All rights reserved.