Fortinet black logo

Devices Managed by FortiOS

Executing custom FortiSwitch scripts

Copy Link
Copy Doc ID b66bd869-148d-11eb-96b9-00505692583a:173262
Download PDF

Executing custom FortiSwitch scripts

From the FortiGate unit, you can execute a custom script on a managed FortiSwitch unit. The custom script contains generic FortiSwitch commands.

NOTE: FortiOS 5.6.0 introduces additional capabilities related to the managed FortiSwitch unit.

This section covers the following topics:

Creating a custom script

Use the following syntax to create a custom script from the FortiGate unit:

config switch-controller custom-command

edit <cmd-name>

set command "<FortiSwitch_command>"

end

NOTE: You need to use %0a to indicate a return.

For example, use the custom script to set the STP max-age parameter on a managed FortiSwitch unit:

config switch-controller custom-command

edit "stp-age-10"

set command "config switch stp setting %0a set max-age 10 %0a end %0a"

end

Executing a custom script once

After you have created a custom script, you can manually execute it on any managed FortiSwitch unit. Because the custom script is not bound to any switch, the FortiSwitch unit might reset some parameters when it is restarted.

Use the following syntax on the FortiGate unit to execute the custom script once on a specified managed FortiSwitch unit:

execute switch-controller custom-command <cmd-name> <target-switch>

For example, you can execute the stp-age-10 script on the specified managed FortiSwitch unit:

execute switch-controller custom-command stp-age-10 S124DP3X15000118

Binding a custom script to a managed switch

If you want the custom script to be part of the managed switchʼs configuration, the custom script must be bound to the managed switch. If any of the commands in the custom script are locally controlled by a switch, the commands might be overwritten locally.

Use the following syntax to bind a custom script to a managed switch:

config switch-controller managed-switch

edit "<FortiSwitch_serial_number>"

config custom-command

edit <custom_script_entry>

set command-name "<name_of_custom_script>"

next

end

next

end

For example:

config switch-controller managed-switch

edit "S524DF4K15000024"

config custom-command

edit 1

set command-name "stp-age-10"

next

end

next

end

Executing custom FortiSwitch scripts

From the FortiGate unit, you can execute a custom script on a managed FortiSwitch unit. The custom script contains generic FortiSwitch commands.

NOTE: FortiOS 5.6.0 introduces additional capabilities related to the managed FortiSwitch unit.

This section covers the following topics:

Creating a custom script

Use the following syntax to create a custom script from the FortiGate unit:

config switch-controller custom-command

edit <cmd-name>

set command "<FortiSwitch_command>"

end

NOTE: You need to use %0a to indicate a return.

For example, use the custom script to set the STP max-age parameter on a managed FortiSwitch unit:

config switch-controller custom-command

edit "stp-age-10"

set command "config switch stp setting %0a set max-age 10 %0a end %0a"

end

Executing a custom script once

After you have created a custom script, you can manually execute it on any managed FortiSwitch unit. Because the custom script is not bound to any switch, the FortiSwitch unit might reset some parameters when it is restarted.

Use the following syntax on the FortiGate unit to execute the custom script once on a specified managed FortiSwitch unit:

execute switch-controller custom-command <cmd-name> <target-switch>

For example, you can execute the stp-age-10 script on the specified managed FortiSwitch unit:

execute switch-controller custom-command stp-age-10 S124DP3X15000118

Binding a custom script to a managed switch

If you want the custom script to be part of the managed switchʼs configuration, the custom script must be bound to the managed switch. If any of the commands in the custom script are locally controlled by a switch, the commands might be overwritten locally.

Use the following syntax to bind a custom script to a managed switch:

config switch-controller managed-switch

edit "<FortiSwitch_serial_number>"

config custom-command

edit <custom_script_entry>

set command-name "<name_of_custom_script>"

next

end

next

end

For example:

config switch-controller managed-switch

edit "S524DF4K15000024"

config custom-command

edit 1

set command-name "stp-age-10"

next

end

next

end