Skip to main content
Contributor
April 18, 2008
Question

Execute commands from a script

  • April 18, 2008
  • 4 replies
  • 2764 views
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

    4 replies

    abelio
    SuperUser
    SuperUser
    April 18, 2008
    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.
    Contributor
    April 18, 2008
    Thank you Abel, I' ll give it a try!
    Contributor
    April 21, 2008
    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
    SuperUser
    SuperUser
    April 21, 2008
    Cool, i' ll see that module too; thanks for the input
    UkWizard
    New Member
    April 21, 2008
    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.