- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Execute commands without yes/no confirmation
Dear experts,
any options to execute the command without confirmation?
eg:
FG01 # execute reboot
This operation will reboot the system !
Do you want to continue? (y/n)
How to pass the `yes` to the command line itself instead of interactive input?
Thanks in advance.
- Labels:
-
FortiGate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Gineesh,
what is the reason for this? Automated reboot via SSH script?
Best regards,
Markus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes, for programmatic operations which are not possible using API's.
Like image update, reboot etc.
We are trying API as well in parallel.
Created on ‎06-10-2022 12:00 AM Edited on ‎06-10-2022 12:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For the sake of completeness, REST API does support reboot and upgrade operations:
POST /api/v2/monitor/system/os/reboot
{"event-log-message": "optional comment"}
POST /api/v2/monitor/system/firmware/upgrade
{"source": "upload,
"file_content": "base-64-encoding-of-the-firmware-image"}
Or since you mentioned ansible:
https://docs.ansible.com/ansible/latest/collections/fortinet/fortios/fortios_monitor_module.html
Relevant "selectors":
- reboot.system.os
- upgrade.system.firmware
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HI @pminarik
Thank you for sharing those. Yes, those are valid but our issue was with direct upload to TFTP as well. I could not find the API section (not sure I missed) to backup to tftp using API or software upgrade from TFTP server.
Reg. fortios_monitor module, I am still working on that as there is a bug (?) with the selector.
selector: 'system_config_backup'
When I execute it, module complains that the system_config_backupis not a valid option !!!
I will raise an issue in the repo anyway as I prefer the module way of doing it rather than passing raw commands to the fortios devices :)
Thank you again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not being a bash expert, but I use something like this to simulate input on the FortiGate shell:
#!/bin/sh
FGTVAR="/root/scripts/fortigate.var"
FSSH="ssh admin@192.168.200.1"
echo "config vdom" >> $FGTVAR
echo "edit root" >> $FGTVAR
etc...
echo "end" >> $FGTVAR
echo "exit" >> $FGTVAR
sleep 1
$FSSH < $FGTVAR
exit 0
You might be able to adapt it as such:
#!/bin/sh
FGTVAR="/root/scripts/fortigate.var"
FSSH="ssh admin@192.168.200.1"
echo "exec reboot" >> $FGTVAR
echo "y" >> $FGTVAR
sleep 1
$FSSH < $FGTVAR
exit 0
Best regards,
Markus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot @Markus_M
I was trying last night and found a "Y" on next line is working now ! (I tried this several times last night and it was not working. strange !)
See my Ansible code now
- name: FortiGate Update Software
raw: |
execute restore image tftp {{ fortios_image_filename }} {{ tftp_server }}
Y
register: update_status
ignore_errors: yes
Thank you so much for advising with that shell and trigger some spark :)
