[j-nsp] Running Scripts

Phil Shafer phil at juniper.net
Tue Mar 21 09:13:30 EST 2006

"Vladimir S. Blazhkun" writes:
>Seems this is not a right way to do this. Better if you will write a
>bash/perl script which will put its output into text file. Than simple
>load whole file via 'load merge file' and than commit.

Another alternative is to use the JUNOScript API to toss config
onto the router.  The API exposes a set of RPCs such as "get-configuration",
"load-configuration", and "commit-configuration" that allow you to 
configure your router in a simple, programmatic manner.  There are
perl libraries and docs available at:


The basics are simple (snipped from one of the examples):

    my %deviceinfo = (
            access => $access,
            login => $login,
            password => $password,
            hostname => $hostname);
    my $jnx = new JUNOS::Device(%deviceinfo);
    die unless $jnx;
    my $res = $jnx->lock_configuration();
    my $err = $res->getFirstError();
    die if $err;
    eval {
        $res = $jnx->load_configuration(
                format => $config_format, 
                action => $load_action,
                configuration => $doc);
    die if $@;
    my $err = $res->getFirstError();
    die if $err;
    $res = $jnx->commit_configuration();
    my $err = $res->getFirstError();
    die if $err;

The config can be in either text or xml format.  See the docs for
more details.


P.s.:  Yes, I'm still waiting for my first j-nsp Commit Scripts question ;^)

More information about the juniper-nsp mailing list