2

Matlab R2015a

Hello,

In order to programmatically ssh connect I made an expect script as explained in

ssh connect and commands programmatically

  #!/usr/bin/expect
  set login "any_user"
  set addr "some_address"
  set pw "any_pwd"

  spawn ssh -t $login@$addr
  expect "$login@$addr\'s password:"
  send "$pw\r"
  expect "~" ; # put here string from your server prompt
  send "mkdir some_dir\r"
  interact

I called this script LoginSSH.sh (of course, with my own data), then I run this command in the Linux console without problems:

./LoginSSH.sh

The idea was to run this command from Matlab with system():

  scmd='./LoginSSH.sh'

  [status,cmdout]=system(scmd)

But for some reason Matlab has some problems to execute the script via system(). This is the output:

status =

     1  

cmdout = 



 OpenSSL version mismatch. Built against 100020af, you have 1000107f

  send: spawn id exp4 not open
      while executing
  "send "$pw\r""
      (file "./LoginSSH.sh" line 8)

I can even run the command in Python:

  import os
  from subprocess import call
  call(["./LoginSSH.sh"])

again, without any problems.

What could be the reason Matlab won't like to run the shell script?

Thanks in advance.

jleon

5
  • do you know autoexpect? sometimes highlight some missing stuff in the script Commented Oct 29, 2018 at 19:17
  • 1
    Could be library path issue. system command launched from MATLAB could have different versions of libraries present in the path. Try removing any environment variables that set library paths in your script or launch another shell for your script. Commented Oct 29, 2018 at 20:27
  • @Navan, but how is that Python runs the script without any problems? How do I make sure Matlab uses the same libraries than the shell? My script does not explicitly set any environmental variables. Commented Oct 29, 2018 at 22:44
  • 1
    Try executing env -i ./LoginSSH.sh through the system function. env -i starts the given script without inheriting MATLAB's environment. MATLAB sets a lot of variables in the shell before starting (the matlab command is a shell script that prepares the environment and then launches the MATLAB binary). Commented Oct 30, 2018 at 5:31
  • Thanks Cris Luengo. I tried env -i ./LoginSSH.sh but it last forever and never returns (until Ctrl-D). If I run ssh -V both in OS shell and Matlab command it gives different versions for OpenSSL. So I guess Matlab is trying to use a different version of OpenSSL. If I run env (again, in both sides) to get a list of the different environment variables I don't see something that has to do with it. I just want Matlab to run the same version that is run in the Linux shell. Thanks in advance, jleon Commented Nov 2, 2018 at 20:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.