Skip to main content
vraev
Staff
Staff
October 6, 2025

Technical Tip: BASH script for retrieving of FortiGate configurations through FortiManager

  • April 16, 2026 at 1:03 PM
  • 1 reply
  • 781 views
Description

 

This article will provide a BASH script that will help make a mass retrieval of FortiGate configurations from FortiManager.

 

Scope

 

FortiManager.

 

Solution

 

The following programs are required on the GNU/Linux distribution in use.

  • AWK.
  • SED.
  • SSHPASS.
  • SSH Client.

 

The following links can be used to give more information, options, and some security tips:

Technical Tip: Continuous debug monitoring with Bash and Crontab

Technical Tip: BASH script to retrieve debug information periodically with SSH and SSH multiplexing

 

To achieve the retrieval of all of the current configurations from all of the FortiGates on board from the FortiManager, the following script will be made in two parts.

First, retrieve through SSH connection the list of FortiGates and parse their OIDs.

Second, make a connection to the FortiManager and request to retrieve the current configuration using the OIDs of the FortiGates.

 

#!/bin/bash # Author: vraev # Source: https://community.fortinet.com  USERNAME="json" HOSTS=('10.5.144.44') COMMAND='diagnose dvm device list'   function sshtofmg()  {  export SSHPASS='SomePassH3R3!'   sshpass -e ssh -ttn -o BatchMode=no -o StrictHostKeyChecking=no ${USERNAME}@${HOSTNAME} ${@}  }  function parser() { tail +5 | column -t | awk '{print $2}' | grep ^[1-9]  }  function retrieve() { for HOSTNAME in "${HOSTS[@]}" do sshtofmg $COMMAND | (parser) > outputfmg.log sed -i 's/^/diagnose test deploymanager reloadconf /g' outputfmg.log  while read -r line; do    sshtofmg "$line" </dev/null done < "outputfmg.log"   done exit 1 }   #cd ~/ssh_test/ retrieve > retrieve.log

 

To review the logs regarding the operations.
Go to System settings -> Event logs.

 

FMG_elogs.png

 

Related article:
Technical Tip: Retrieve FortiGate configuration in FortiManager using JSON API

1 reply

zshangyu
Staff
Staff
October 23, 2025

Does this actually work and get the configuration data?

Thought Leadership. Security Summit. Thursday, November 12th, PGA National Resort, Palm Beach Gardens, FL.
Thought Leadership. Security Summit. Thursday, October 8th. Disney's Grand Californian Hotel & SPA, Anaheim, CA.
Security Operations Summit: Modernize SecOps. Operate AI-Native.AMER: November 4 | 9:00 AM PST. India and SAARC: November 5 | 10:00 AM IST. EMEA: November 5 | 10:30 AM CET. APAC: November 5 | 11:00 AM SGT