Configuration Guide Vol. 1


21.2.6 Starting Scripts

Start the created script as a command script, a resident script, or an event startup script.

<Structure of this section>

(1) Starting the Command Script

When an operation command python is executed with the script file name specified, the command script starts.

Figure 21-9 Example of Executing the Python Command (Starting Script)
# python sample.py                                ..1
  1. Start sample.py file.

You can also start the installed script as a module, as shown in the following figure.

Figure 21-10 Example of execution of the python command (startup of the module)
# install script sample.py                        ..1
# python -m sample                                ..2
  1. Install sample.py file on the Switch.

  2. Start sample.py file as a module. When starting as a module, omit the extension.

(2) Starting resident scripts

To start the resident script, the following two settings are required.

The resident script starts when both registrations are completed. The following figure shows an example of setting a resident script.

Figure 21-11: Example of setting resident scripts
# install script sample.py                        ..1
# configure
(config)# resident-script 1 python sample.py      ..2
(config)# 
  1. Install sample.py file on the Switch.

  2. Register sample.py file in the script ID 1 of the resident script. Sample.py starts when you register.

(3) Starting the Event Startup Script

To start the event startup script, three settings are required:

After these registration, the event startup script starts when a monitoring event is detected.

The following figure shows an example of setting the event startup script when the monitoring event is used as timer monitoring.

Figure 21-12: Example of event startup script settings (timer monitoring)
# install script sample.py                        ..1
# configure
(config)# event manager applet INTERVAL100s       ..2
(config-applet)# event timer interval 100         ..3
(config-applet)# action 1 python sample.py        ..4
(config-applet)# 
  1. Install sample.py file on the Switch.

  2. Creates an applet with the applet name INTERVAL100s and enters the configuration mode of the applet.

  3. Registers timer monitoring for generating events at 100 second intervals.

  4. Registers sample.py file to sequence number 1 of the action. Sample.py starts every 100 seconds at the time of registering.

The following figure shows an example of setting the event startup script when monitoring events are used as operation message monitoring.

Figure 21-13: Example of event startup script settings (operation message monitoring)
# install script sample.py                        ..1
# configure
(config)# event manager applet PORT_UP            ..2
(config-applet)# event sysmsg message-id 25011001 ..3
(config-applet)# action 1 python sample.py        ..4
(config-applet)# 
07/07 12:00:00 01S E4 PORT GigabitEthernet1/0/1 25011001 1350:000000000000 Port up.
                                                  ..5
(config-applet)# 
  1. Install sample.py file on the Switch.

  2. Creates an applet with the applet name PORT_UP and enters the configuration mode of the applet.

  3. Registers operation message monitoring, which monitors operation message output for which the message identifier is 25011001.

  4. Registers sample.py file to sequence number 1 of the action.

  5. Sample.py starts when an operation message corresponding to the monitoring condition (message identifier 25011001) is output.

(4) Checking the Startup Script PID

OS assigns an identifier called PID(Process ID to the invoked scripts. Different PID are assigned to distinguish between different scripts, even if you invoke the same scripts more than once.

PID assigned to the scripts can be checked using the operation command show script running-state. The following figure shows a sample PID displayed when the same scripting is started from two or more terminals.

Figure 21-14: Checking PID of the startup scripts
# show script running-state                       ..1
Date 20XX/02/05 18:17:40 UTC
 
[operation command]                               ..2
  command line args: python sample.py
  PID: 2213
  start time: 20XX/02/05 18:17:24 UTC
 
  command line args: python sample.py
  PID: 1968
  start time: 20XX/02/05 18:17:26 UTC
 
[applet]                                          ..3
  applet name: INTERVAL100s
  action sequence: 1
  command line args: python sample.py
  PID: 11700
  start time: 20XX/02/05 18:17:38 UTC
 
[resident]                                        ..4
  script id: 1
  command line args: python sample.py
  state: Running
  PID: 1977
  start time: 20XX/02/05 18:17:29 UTC
# 
  1. Displays the script that is currently running.

  2. You can check the script that is running as a command script.

    In this case, you can verify that the scripts with PID 2213 and 1968 are running.

  3. You can check the scripts that are running as event startup scripts.

    In this case, you can verify that PID 11700 scripting is running.

  4. You can check the script that is running as a resident script.

    In this case, you can verify that the scripting with PID 1977 is running.