Hi, in order to commit only at the end of the script, you should use the jcs:execute function instead of the jcs:load-configuration.
I'd also suggest you to lock the configuration at the beginning of the script.
So these are the steps to follow:
1. Open the connection and lock the configuration database, before entering the for-each cycle:
var $connection = jcs:open();
var $config-lock = <lock-configuration>;
var $lock-results = jcs:execute( $connection, $config-lock );
if ($lock-results//xnm:error) { <xnm:error>{<message> "Configuration locking failed!";}}
2. within the for-each cycle, load each configuration change:
var $load-configuration = <load-configuration> {
copy-of $config-changes;
}
var $load-results = jcs:execute( $connection, $load-configuration );
if ($load-results//xnm:error) { <xnm:error>{<message> "Configuration loading failed!";}}
3. After the for-each cycle, commit the configuration, unlock the database and close the connection:
var $commit-configuration = <commit-configuration>;
var $commit-results = jcs:execute( $connection, $commit-configuration );
var $config-unlock = <unlock-configuration>;
var $unlock-results = jcs:execute( $connection, $config-unlock );
if ($unlock-results//xnm:error) { <xnm:warning>{<message> "Configuration unlocking failed!";}}
var $close-results = jcs:close( $connection );
if ($close-results//xnm:error) { <xnm:warning>{<message> "Disconnection from the router failed!";}}
You can find some reference about those functions in the Day One book "This Week: Junos Automation Reference for SLAX 1.0".
I hope it helps!
Mattia