Executing shell commands from SLAX scripts

Starting with 14.1, it’s possible to execute shell commands from SLAX scripts.

This is an example of how you can get the output of the shell command “ifconfig me0”.

First configure the OP script like this:

{master:0}[edit]
lab@ex4550# show system scripts 
op {
    file script.slax;
}

{master:0}[edit]
lab@ex4550#


And then execute it:

{ex4550:0}
lab@icosium> show version | match Junos: 
Junos: 14.1X53-D10.1

{ex4550:0}
lab@icosium> op ?
Possible completions:
  invoke-debugger      Invoke script in debugger mode
  script               
  url                  Execution of remote op script
{master:0}
lab@ex4550> op script    
me0:    encaps: ether; framing: ether
        flags=0x3/0x8000 <PRESENT|RUNNING>
        curr media: i802 54:e0:32:86:f8:fd
me0.0:  flags=0x8000 <UP|MULTICAST>
        inet primary mtu 1500 local=172.30.158.163 dest=172.30.158.0/23 bcast=172.30.159.255

{master:0}
lab@ex4550>

This is the script:

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";

var $local = jcs:open();
match / {
    <op-script-results> {
        var $rpc = {
            <request-shell-execute> {
                <command> "ifconfig me0";
            }
        }
        var $result = jcs:execute($local,$rpc);
        copy-of $result;
        expr jcs:close($local);
    }
}

Of course this is just a simple example with no real value.

In my current role, I had a lot of occasions where this could have been handy and I hope others will find this useful.

 

 

 

The following two tabs change content below.

Paris ARAU

Paris ARAU is a networking professional with strong background on routing and switching technologies. He is a holder of CCIE R&S and dual JNCIE(SP and ENT). The day to day work allows him to dive deeply in networking technologies. Part of the continuously training, he is focusing on Software Defined Network and cloud computing.

Comments

This post currently has 2 responses

  • Hi Paris ARAU,

    I have some doubt regarding the auto backup of juniper devices through sftp. Please let me know how it can be done.
    1) do we need to enable sftp on juniper devices, if yes then what are the commands to do it?
    2) what are commands for auto backup in juniper for sftp?
    3) I am using ex4300, qfx5100, ex2200, mx480 and srx3400 devices of juniper and the remote server where the backup will be stored is Ubuntu 14.04?

    Please help me to resolve the issue.

    • Hi Mukesh,

      Is this working for you?

      archival {
      configuration {
      transfer-on-commit;
      archive-sites {
      tftp://1.1.1.1;
      }
      }
      }

      Thanks,
      Paris

Leave a Reply

Your email address will not be published. Required fields are marked *

Sidebar



%d bloggers like this: