Created on
01-11-2021
10:00 AM
Edited on
07-21-2025
02:02 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 10MB (set output-size), calculate and monitor the RAM usage. Improper use of the auto-script may trigger a conserve mode.
Note:
Some commands will not work with the auto-script on older firmware versions.
Support for further commands like 'diagnose test app xxx', 'diagnose wad xxx', 'diagnose ips xxx' was added in FortiOS 7.6.1 and above.
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.
Example 1: Auto-script for sending firewall configuration 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:
Example 2: Auto-script for sending firewall configuration backup to an FTP server:
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:
Note: It is possible to add multiple CLI commands in the auto-script.
Example 3: Checking the generic status of the device using multiple commands with the help of Auto-script:
'get system status' and 'get system performance status' are the commands used for this.
config system auto-script
edit "status"
set interval 300
set repeat 0
set start auto
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.
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 from running before making any modifications.
config system auto-script
edit "restart-wad"
set interval 3600
set repeat 65535
set start auto
set script "diag test app wad 99"
next
end
config system auto-script
edit "OSPF_routing_script"
set interval 5
set repeat 50000
set start auto
set script "
get sys stat
get router info routing-table ospf
get system arp
get router info ospf neighbor
"
end
config system auto-script
edit "clear_dhcp_lease"
set interval 600
set repeat 65535
set start auto
set script "
execute dhcp lease-list
execute dhcp lease-clear all
"
next
end
config system auto-script
edit "clear_dhcp_lease"
set interval 600 <---- interval of choice
set repeat 0
set start auto
set script "diagnose user device clear"
next
end
The temporary files of the auto-script are stored in '/tmp/$$auto-script$$/'.
The total size of all auto-script files can be checked with the following commands:
fnsysctl df -k
fnsysctl df -h
fnsysctl ls -al /tmp/$$auto-script$$/
fnsysctl du -aLL /tmp/$$auto-script$$
Example outputs:
fnsysctl df -h
Filesystem Size Used Available Use% Mounted on
none 1.4G 362.2M 1.0G 25% /tmp
... cut ...
fnsysctl ls -al /tmp/$$auto-script$$/
drwxr-xr-x 2 0 0 Tue Jan 7 10:22:52 2025 60 .
drwxrwxrwt 56 0 0 Tue Jan 7 10:30:14 2025 5060 ..
-rw-r--r-- 1 0 0 Tue Jan 7 10:22:48 2025 11617598 auto-script_test.out <- 11,08 MB.
fnsysctl du -aLL /tmp/$$auto-script$$
11348 /tmp/$$auto-script$$/auto-script_test.out
11348 /tmp/$$auto-script$$ <----- 11,08 MB.
Related documents:
CLI reference: config system auto-script
Technical Tip: How to restart/kill all processes with the 'fnsysctl' command
Technical Tip: Configuring an automated script for daily FortiGate configuration backups
Technical Tip: How to clear the unit inventory list from FortiGate in particular interval
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 2025 Fortinet, Inc. All Rights Reserved.