Automation

last person joined: yesterday 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  OP SCRIPT DOESN´T RUN

    Posted 06-23-2016 15:41

    Hi

    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";
    ns math = "http://exslt.org/math";
    ns func extension = "http://exslt.org/functions";
    ns wizard extension = "http://xml.juniper.net/wizard";
    ns ext = "http://xmlsoft.org/XSLT/namespace";

    import "../import/junos.xsl";
    import "../import/lib-util.slax";
    import "../import/lib-wizard.slax";

    var $usage = "Este script elimina el usuario especificado ";
    var $temp = jcs:output($usage);
    var $usuario = jcs:get-input("Ingrese usuario a borrar: ");
    var $config-changes = {
    <configuration>{
    <system>{
    <login>{
    <user>{
    <name delete="delete"> $usuario;
    }
    }
    }
    }
    }
    var $load-action = "merge";
    var $options := {
    <commit-options> {
    <log> "borrado usuarios " _ $usuario;
    }
    }
    var $conn_handle = jcs:open();
    var $results := {
    call jcs:load-configuration($action=$load-action, $commit-options=$options, $configuration=$config-changes, $connection=$conn_handle);
    }
    var $close-results = jcs:close($conn_handle);
    if ($results//xnm:error) {
    for-each ($results//xnm:error) {
    <output> message;
    }
    }
    if ($results//xnm:warning) {
    for-each ($results//xnm:warning) {
    <output> message;
    }
    }

     

    But when I run have this mistake message:

    error: ^

    error: error: /var/db/scripts/op/delete-user.slax: 1 error detected during parsing

    error: error reading stylesheet: delete-user.slax

    error: /var/db/scripts/op/delete-user.slax:40: error: /var/db/scripts/op/delete-user.slax:39: parse error, unexpected K_IF before 'if':
    error: ^
    error: error: /var/db/scripts/op/delete-user.slax: 1 error detected during parsing
    error: error reading stylesheet: delete-user.slax

     

    Do you know what is it wrong here?

     

    Regards



  • 2.  RE: OP SCRIPT DOESN´T RUN
    Best Answer

     
    Posted 06-27-2016 06:18

    Hi,

     

    I think that there are a couple of issues here.

     

    Missing the match and results

     

    match / {
        <op-script-results> {
         ....
        }
    }

    Incorrect configuration change.

     

     

    var $config-changes = {
        <configuration> {
            <system> {
                <login> {
                    <user delete="delete"> $usuario;
                }
            }
        }
    }

    Putting this all together (I also removed some namespace and includes, as I don't have the files that you list), produces the following 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";
    
    match / {
        <op-script-results> {
            var $usage = "Este script elimina el usuario especificado ";
            var $temp = jcs:output($usage);
            var $usuario = jcs:get-input("Ingrese usuario a borrar: ");
            var $config-changes = {
                <configuration> {
                    <system> {
                        <login> {
                            <user delete="delete"> $usuario;
                        }
                    }
                }
            }
            var $load-action = "merge";
            var $options := {
                <commit-options> {
                    <log> "borrado usuarios " _ $usuario;
                }
            }
            var $conn_handle = jcs:open();
            var $results := {
                call jcs:load-configuration($action=$load-action, $commit-options=$options, $configuration=$config-changes, $connection=$conn_handle);
            }
            var $close-results = jcs:close($conn_handle);
            if ($results//xnm:error) {
                for-each ($results//xnm:error) {
                    <output> message;
                }
            }
            if ($results//xnm:warning) {
                for-each ($results//xnm:warning) {
                    <output> message;
                }
            }
        }
    }
    

    Testing this produces the expected results.

     

    # set system login user fred class super-user authentication plain-text-password
    
    [edit]
    # commit and-quit
    commit complete
    Exiting configuration mode
    
    > show configuration system login user fred
    uid 2003;
    class super-user;
    authentication {
        encrypted-password "$1$BbbYr7iw$Sodx3HcyTPNLb38qJrsGa1"; ## SECRET-DATA
    }
    
    > op forum
    Este script elimina el usuario especificado
    Ingrese usuario a borrar: fred
    
    > show configuration system login user fred
    
    > show system commit
    0   2015-12-08 12:03:40 UTC by space via junoscript
        borrado usuarios fred

    Hope that this helps.

     

    Regards,

    Andy

     



  • 3.  RE: OP SCRIPT DOESN´T RUN

    Posted 06-27-2016 07:20

    Thx a lot, the result is sucessful!