Created on 01-11-2021 10:00 AM Edited on 10-23-2024 03:30 AM By Jean-Philippe_P
Description
This article describes how to use the automated scripting on FortiGate.
Scope
FortiGate.
Solution
In FortiOS it is possible to configure auto-scripts and this feature can be used for various purposes.
Important note:
The auto-script output is stored in the RAM, so if running multiple scripts with a maximum of default 10MB (set output-size), calculate and monitor the RAM usage. Improper use of the auto-script may trigger a conserve mode.
Note:
If the output size is exceeded, the script will stop. Consider the auto-script as a temporary installation only, it is good for time-based troubleshooting.
CLI example to send a backup to a TFTP server:
config system auto-script
edit "backup"
set interval 120 <----- Interval of time in seconds to execute the task, for example for 2 minutes.
set repeat 0 <----- Time of repeats, 0 means always. The default is 1.
set start auto <---- If set to auto the process would start by the system automatically, manual is the default where it is necessary to start the process.
set script "execute backup config ftp backup.conf 10.10.10.2 test test"
next
end
Whereas in this example:
CLI example to send a backup to the FTP server in FortiGates with VDOMs:
config system auto-script
edit "backup"
set interval 120
set repeat 0
set start auto
set script "
config global
execute backup config ftp backup.conf 10.10.10.2 test test"
next
end
Where:
Add multiple CLI commands in the CLI script.
For example, if it is desired to check the generic status output from the CLI like:
get system status
get system performance status
FGT # config system auto-script
FGT (auto-script) # edit "status"
FGT (status) # set interval 300
FGT (status) # set repeat 0
FGT (status) # set start auto
FGT (status) # set script " <----- Press enter key here add the first command.
get system status <----- Press the enter key here and add the second command in the next line.
get system performance status" <----- Make sure that the last command ends with a double quotation mark.
Once a double quotation mark is added, it will redirect to the command prompt.
FGT (status) # sh
config system auto-script
edit "status"
set interval 120
set repeat 0
set start auto
set script "
get system status
get system performance status
"
next
end
To check the script output stored in the file.
From GUI:
Go to System -> Advanced -> Scheduled Script.
Select the 'Download' button from the 'Status' field for the selected script and Open the file to read the output.
Modifying a running script will show an output (error) as shown below. So, the script must be stopped running before making any modifications.
Related documents:
Technical Tip: How to restart/kill all processes with the 'fnsysctl' command
Technical Tip: Configuring an automated script for daily FortiGate configuration backups
The Fortinet Security Fabric brings together the concepts of convergence and consolidation to provide comprehensive cybersecurity protection for all users, devices, and applications and across all network edges.
Copyright 2024 Fortinet, Inc. All Rights Reserved.