Support Support Downloads Knowledge Base Case Manager My Juniper Community

Knowledge Base

Search our Knowledge Base sites to find answers to your questions.

Ask All Knowledge Base Sites All Knowledge Base Sites JunosE Defect (KA)Knowledge BaseSecurity AdvisoriesTechnical BulletinsTechnotes Sign in to display secure content and recently viewed articles

[MX] Commit script to prevent interface deletion

0

0

Article ID: KB32973 KB Last Updated: 09 Jan 2020Version: 2.0
Summary:

During provisioning on MX Series routers, users may accidentally delete a router's interface hierarchy by using delete interfaces, causing the entire router to be impacted. To prevent this accidental deletion of interfaces via misconfiguration, a commit script can be used.

This article gives the script that can be used to prevent such accidental deletion.

 

Symptoms:

Deletion of all interfaces and potential loss of router

 

Cause:

Accidental deletion due to misconfiguration

 

Solution:
  1. Create a new file under /var/db/scripts/commit. Root access would be required.

cd /var/db/scripts/commit
vi interface.slax 

Paste and save the below lines:
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 configuration {
 
call error-if-missing($must =
                        interfaces/interface[name='lo0']/unit[name='0']/family/inet/address,
                        $statement = 'interfaces lo0 unit 0 family inet address');
                }
 
error-if-missing ($must, $statement = "unknown", $message = "You deleted the interfaces, not allowed, go sit in your corner. Aborting! Missing mandatory configuration statement") {
   
    if (not($must)) {
        <xnm:error> {
            <edit-path> {
                copy-of $statement;
            }
            <message> {
                copy-of $message;
            }
        }
    }
}
  1. Apply the commit script to the configuration under system scripts:

system {
scripts {
    commit {
        file interface.slax;
    }
}
 

Example

{MASTER}[edit]
lab@router-01# delete interfaces
 
{MASTER}[edit]
lab@router-01# commit
interfaces lo0 unit 0 family inet address
  You deleted the interfaces, not allowed, go sit in your corner. Aborting! Missing mandatory configuration statement
error: 1 error reported by commit scripts
error: commit script failure
 
{MASTER}[edit]
lab@router-01#

 

Modification History:

2020-01-09: Modified solution and added some changes to script

 

Comment on this article > Affected Products Browse the Knowledge Base for more articles related to these product categories. Select a category to begin.

Getting Up and Running with Junos

Getting Up and Running with Junos Security Alerts and Vulnerabilities Product Alerts and Software Release Notices Problem Report (PR) Search Tool EOL Notices and Bulletins JTAC User Guide Customer Care User Guide Pathfinder SRX High Availability Configurator SRX VPN Configurator Training Courses and Videos End User Licence Agreement Global Search