Skip to main content
gineesh
New Member
June 9, 2022
Question

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.

6 replies

Markus_M
Staff & Editor
Staff & Editor
June 9, 2022

Hi Gineesh,

 

what is the reason for this? Automated reboot via SSH script?

 

Best regards,

 

Markus

Best regards, Markus
gineesh
gineeshAuthor
New Member
June 9, 2022

yes, for programmatic operations which are not possible using API's.
Like image update, reboot etc.

We are trying API as well in parallel.

pminarik
Staff
Staff
June 10, 2022

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

Markus_M
Staff & Editor
Staff & Editor
June 9, 2022

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

Best regards, Markus
gineesh
gineeshAuthor
New Member
June 10, 2022

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 :)


 

 

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