- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using purge in CLI scripts
Dear all,
I created a script that first needs to delete table of reserved addressed for DHCP server before it starts creating new entries.
However, purge command requires confirmation from the user and this is something that I don’t know how to achieve inside of the script. If I’m entering commands one by one there is no issue.
I’ve tried with solution recommended here: https://community.fortinet.com/t5/Support-Forum/Inserting-a-PURGE-command-into-a-script/m-p/29958 but without success.
Here are the details:
Script:
config system dhcp server
edit 4
config reserved-address
purge\ny <--breaks here
edit 0
set mac 4c:02:20:5c:65:61
set action assign
next
edit 0
set mac 28:c2:1f:5b:f2:35
set action assign
next
end
OS version is 7.4
Thank you in advance!
- Labels:
-
FortiGate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Milosh
The following works for me:
purge
y
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try using Teraterm instead of Putty as temporary workaround with previous synthax in two lines:
purge
y
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi! Did you get answer? I'm struggling with the same problem right now. I must make CLI script in FortiManager 7.4 that deletes all DHCP servers from FortiGate default configuration. I tried purge /ny and I also tried to add y on other line, but it was worthless for me.
@milosh wrote:Dear all,
I created a script that first needs to delete table of reserved addressed for DHCP server before it starts creating new entries.
However, purge command requires confirmation from the user and this is something that I don’t know how to achieve inside of the script. If I’m entering commands one by one there is no issue.
I’ve tried with solution recommended here: https://community.fortinet.com/t5/Support-Forum/Inserting-a-PURGE-command-into-a-script/m-p/29958 but without success.
Here are the details:
Script:
config system dhcp server
edit 4
config reserved-address
purge\ny <--breaks here
edit 0
set mac 4c:02:20:5c:65:61
set action assign
next
edit 0
set mac 28:c2:1f:5b:f2:35
set action assign
next
end
OS version is 7.4
Thank you in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Tauri
The following worked well for me:
purge
y
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh okai, thanks for answering so fast. I tried it, but it works only if you just copy paste CLI template to FortiGate directly, but I must use CLI templates for ZTP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You can try with a Jinja template and a loop trough the addresses to delete them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tried that as well a dozen times, as it is required in FMG jinja2 scripts. Unfortunately, jinja2 scripts just pre-process on the client side, and cannot read the existing config from the target FGT - only TCL scripts can do that. But, TCL is deprecated according to FTNT sources.
DHCP reservations wind up in the wrong DHCP server if a server is added or removed from the list. It's really a heavy bug. ATM, I help myself by manually purging all DHCP servers on the FGT itself prior to pushing the jinja script from FMG.
Same situation with static routes. You add one, the next is flagged as "no duplicates allowed!" and the script dies.
A shortcut to the FMG dev team really would be helpful, like a 'found bug dropbox'.
