Support Forum
The Forums are a place to find answers on a range of Fortinet products from peers and product experts.
Not applicable

Execute commands from a script

Dear all, I' d like to execute some commands in a FortiMail using a script. I thougth I could do it by passing the commands in an ssh command line from a Linux box, but when I do so, nothing happens. Example: [root@linuxbox /test_dir]# ssh admin@192.168.1.99 ' get config ssh' admin@192.168.1.99' s password: [root@linuxbox /test_dir]# As you can see, nothing happens. The password is correct because when I enter a wrong password, the behavior is different: [root@linuxbox /test_dir]# ssh admin@192.168.1.99 ' get config ssh' admin@192.168.1.99' s password: Permission denied, please try again. admin@192.168.1.99' s password: [root@linuxbox /test_dir]# If I login with ssh and execute the same command, it shows somthing: =[ BEGIN ssh ]============================= [root@linuxbox /test_dir]# ssh admin@192.168.1.99 admin@192.168.1.99' s password: Type ? for a list of commands. mx1 # get config ssh set system interface port1 config allowaccess https ping ssh telnet set system interface port2 config allowaccess https ping ssh set system interface port3 config allowaccess https ping ssh mx1 # exit Connection to 192.168.1.99 closed. [root@linuxbox /test_dir]# =[ END ssh ]=============================== Is there any way to send a command to the FortiMail from a script? Regards, Marcos
5 REPLIES 5
abelio
SuperUser
SuperUser

you need ' expect' a software package to write scripts dealing with dialogues like the above one. Google for ' expect' and examples for your linux distro; it' s a very nice piece of software.

regards




/ Abel

regards / Abel
Not applicable

Thank you Abel, I' ll give it a try!
Not applicable

I' ve used the Perl module " Net::SSH::Expect" and worked perfectly! Just had to add the " timeout" parameter to the constructor of the " Net::SSH::Expect" object since my FortiMail box was a little bit lazy to answer and the default timeout is just 1sec. Thank you again for this tip.
abelio

Cool, i' ll see that module too; thanks for the input

regards




/ Abel

regards / Abel
UkWizard
New Contributor

you could also consider teraterms macro function, or kiwi' s cat-tools utility. I have had success with both of the above and also using a linux expect script.
UK Based Technical Consultant FCSE v2.5 FCSE v2.8 FCNSP v3 Specialising in Systems, Apps, SAN Storage and Networks, with over 25 Yrs IT experience.
UK Based Technical Consultant FCSE v2.5 FCSE v2.8 FCNSP v3 Specialising in Systems, Apps, SAN Storage and Networks, with over 25 Yrs IT experience.
Labels
Top Kudoed Authors