Fortinet white logo
Fortinet white logo

Cookbook

Configuration scripts

Configuration scripts

Configuration scripts are text files that contain CLI command sequences. They can be created using a text editor, entered directly in the CLI, copied from a CLI console, or recorded using the CLI Console Record CLI Script function.

Scripts can be scheduled to run at specific intervals a specified number of numbers, or uploaded, run once, and then deleted. Scheduled scripts can only be created using the CLI, but can be run, stopped, deleted, and downloaded from the GUI.

Scripts can be used to run the same task on multiple devices. For example, if your devices use the same security policies, you can enter or record the commands to create those policies in a script, and then run the script on each device. You could also create the policies in the GUI, and then copy and paste the CLI commands from the CLI Console using the show command.

If the FortiGate is managed by FortiManager, scripts can be uploaded to FortiManager and then run on any other FortiGates that are managed by that FortiManager. See Scripts in the FortiManager Administration Guide.

Tooltip

A comment line in a script starts with the number sign (#). Comments are not be executed.

To run a script using the GUI:
  1. Go to System > Advanced.
  2. Expand Configuration Scripts.
  3. Click Upload and Run a New Script.
  4. Locate the text file containing the script on your management computer, then click Open.

    The script runs immediately, and the Script Execution History table is updated, showing if the script ran successfully.

To add a script to backup the configuration to a TFTP server every five minutes:
config system auto-script
    edit "backup"
        set interval 300
        set repeat 0
        set start auto
        set script "execute backup config tftp backup.conf 10.10.10.2"
    next
end
To add a script to backup the configuration of a FortiGate with VDOMs enabled to a FTP server every ten minutes for the next hour:
config system auto-script
    edit "backup"
        set interval 600
        set repeat 7
        set start auto
        set script "
config global
execute backup config ftp BackupFile.conf 10.10.10.2 username password" 
    next
end
To add a script to get the system status and performance every seven minutes using up to 20MB of storage:
config system auto-script
    edit "status"
        set interval 420
        set repeat 0
        set start auto
        set output-size 20
        set script "
get system status
get system performance status"
    next
end
To stop a scheduled script:
  1. Go to System > Advanced.
  2. In the Scheduled Scripts area, locate the script, then click the Stop Running Scheduled Script icon.

    The Status changes to Not Running, and the Run Scheduled Script icon becomes available.

To view the results of a scheduled script:
  1. Go to System > Advanced.
  2. In the Scheduled Scripts area, locate the script, then click the Download Scheduled Script Running Result icon.
  3. Save the .OUT file to the management computer, or open it directly in a text editor.

Configuration scripts

Configuration scripts

Configuration scripts are text files that contain CLI command sequences. They can be created using a text editor, entered directly in the CLI, copied from a CLI console, or recorded using the CLI Console Record CLI Script function.

Scripts can be scheduled to run at specific intervals a specified number of numbers, or uploaded, run once, and then deleted. Scheduled scripts can only be created using the CLI, but can be run, stopped, deleted, and downloaded from the GUI.

Scripts can be used to run the same task on multiple devices. For example, if your devices use the same security policies, you can enter or record the commands to create those policies in a script, and then run the script on each device. You could also create the policies in the GUI, and then copy and paste the CLI commands from the CLI Console using the show command.

If the FortiGate is managed by FortiManager, scripts can be uploaded to FortiManager and then run on any other FortiGates that are managed by that FortiManager. See Scripts in the FortiManager Administration Guide.

Tooltip

A comment line in a script starts with the number sign (#). Comments are not be executed.

To run a script using the GUI:
  1. Go to System > Advanced.
  2. Expand Configuration Scripts.
  3. Click Upload and Run a New Script.
  4. Locate the text file containing the script on your management computer, then click Open.

    The script runs immediately, and the Script Execution History table is updated, showing if the script ran successfully.

To add a script to backup the configuration to a TFTP server every five minutes:
config system auto-script
    edit "backup"
        set interval 300
        set repeat 0
        set start auto
        set script "execute backup config tftp backup.conf 10.10.10.2"
    next
end
To add a script to backup the configuration of a FortiGate with VDOMs enabled to a FTP server every ten minutes for the next hour:
config system auto-script
    edit "backup"
        set interval 600
        set repeat 7
        set start auto
        set script "
config global
execute backup config ftp BackupFile.conf 10.10.10.2 username password" 
    next
end
To add a script to get the system status and performance every seven minutes using up to 20MB of storage:
config system auto-script
    edit "status"
        set interval 420
        set repeat 0
        set start auto
        set output-size 20
        set script "
get system status
get system performance status"
    next
end
To stop a scheduled script:
  1. Go to System > Advanced.
  2. In the Scheduled Scripts area, locate the script, then click the Stop Running Scheduled Script icon.

    The Status changes to Not Running, and the Run Scheduled Script icon becomes available.

To view the results of a scheduled script:
  1. Go to System > Advanced.
  2. In the Scheduled Scripts area, locate the script, then click the Download Scheduled Script Running Result icon.
  3. Save the .OUT file to the management computer, or open it directly in a text editor.