basic ping slax script

1- create or copy the create in:     /var/db/scripts/op/jlk_ping.slax

2- config:  "set system scripts op file jlk_ping.slax"

3- run the script:  

jlk_ping.slax
set system scripts op file jlk_ping.slax


root@QFX5110-2> file show /var/db/scripts/op/jlk_ping.slax
version 1.0;

/* 
 * ping an ip addr
 * 
 * op jlk_ping.slax
 */

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> 
    {
        /* execute the 'ping' command and store the result */
        var $query = { <command> 'ping 12.12.0.2 routing-instance vrouter1 count 10'; }
        var $result = jcs:invoke($query);              

        /* print a header */
        <output>"done";

    }
}
show config
root@QFX5110-2> show configuration routing-instances
vrouter1 {
    instance-type virtual-router;
    interface ge-0/0/2.0;
}
vrouter2 {
    instance-type virtual-router;
    interface ge-0/0/10.0;
}


root@QFX5110-2> show configuration interfaces
ge-0/0/2 {
    unit 0 {
        family inet {
            address 12.12.0.1/30;
        }
    }
}
ge-0/0/10 {
    unit 0 {
        family inet {
            address 12.12.0.2/30;
        }
    }
}


set interfaces ge-0/0/2 unit 0 family inet address 12.12.0.1/30
set interfaces ge-0/0/10 unit 0 family inet address 12.12.0.2/30

set routing-instances vrouter1 instance-type virtual-router
set routing-instances vrouter1 interface ge-0/0/2.0
set routing-instances vrouter2 instance-type virtual-router
set routing-instances vrouter2 interface ge-0/0/10.0


Call op script: op jlk_ping
root@QFX5110-2> op jlk_ping | display json
{
    "output" : [
    {
        "data" : "12.12.0.2\n12.12.0.2\n56\n\n1\n\n0\n12.12.0.2\n64\n64\n10897\n\n\n2\n\n1\n12.12.0.2\n64\n64\n1896\n\n\n2\n2\n0\n1896\n10897\n6396\n4500"
    }
    ]
}

clear interfaces statistics ge-0/0/2.0
monitor interface ge-0/0/2.0