在Mathematica中运行ssh命令

时间:2021-03-31 07:05:41

Lately I've been trying to run a shell ssh command from a Mathematica notebook. I tried several suggested methods with no positive outcome. My search to an answer lead me to the following result:

最近我一直在尝试从Mathematica笔记本上运行shell ssh命令。我尝试了几种没有积极效果的建议方法。我在寻找答案的过程中得出了以下结论:

RunProcess[$SystemShell, All, " ssh <login>@<server> exit "]

RunProcess[$SystemShell, All, " ssh @ exit "]

but this gives a following error

但是这会产生以下错误

<|"ExitCode" -> 127, "StandardOutput" -> "", "StandardError" -> "ssh: /usr/local/Wolfram/Mathematica/10.0/SystemFiles/Libraries/\ Linux-x86-64/libcrypto.so.1.0.0: no version information available \ (required by ssh) ssh: /usr/local/Wolfram/Mathematica/10.0/SystemFiles/Libraries/\ Linux-x86-64/libcrypto.so.1.0.0: no version information available \ (required by ssh) ssh: relocation error: ssh: symbol EVP_aes_128_ctr, version \ OPENSSL_1.0.1 not defined in file libcrypto.so.1.0.0 with link time \ reference "|>

<|“ExitCode”-> 127,“标准输出”->”,“标准输出”->“ssh: / usr/local/wolfram/mathematica /10.0/SystemFiles/ library /\ Linux-x86-64/libcrypto.so.1.0.0:没有版本信息(ssh需要):/ usr/local/wolfram/mathematica /10.0/SystemFiles/ library /\ Linux-x86-64/libcrypto.so.1.0.0:没有版本信息(ssh需要)ssh:迁移错误:ssh: ssh:符号EVP_aes_128_ctr,版本\ OPENSSL_1.0.1未在文件libcry.so.1.0.0中定义,链接时间\引用“|>”

do you have an idea how to fix it?

你知道怎么修理吗?

P.S. My overall goal is to import and export data between external server and Mathematica notebook.

我的总体目标是在外部服务器和Mathematica notebook之间导入和导出数据。

3 个解决方案

#1


0  

Łukasz Gładczuk suggestion should work, but there is a better way to accomplish this.

Łukasz Gładczuk建议应该工作,但是有一个更好的方法来完成这项工作。

RunProcess provides a ProcessEnvironment option that allows you to set environment variables for your process. The default value is Inherited, which means the environment variables are inherited from Wolfram Language, which is what is causing library problems.

RunProcess提供了一个ProcessEnvironment选项,允许您为流程设置环境变量。默认值是继承的,这意味着环境变量是从Wolfram语言继承的,这正是导致库问题的原因。

Run echo $PATH in a terminal to find your path, then use:

在终端中运行echo $PATH查找路径,然后使用:

RunProcess[{"ssh", "user@server"}, ProcessEnvironment -> <|"PATH" -> yourpath|>]

where yourpath is your path, as a string.

你的路径就是你的路径,就像一条线。

#2


2  

I found that Mathematica forces library dependencies. If I use ldd /usr/bin/ssh command in terminal I obtain following output:

我发现Mathematica强制图书馆依赖。如果我在终端使用ldd /usr/bin/ssh命令,我会得到以下输出:

linux-vdso.so.1 => (0x00007fffb31fe000) libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f2a309a7000) libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f2a305cd000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f2a303c8000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f2a301af000) libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f2a2ff94000) libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f2a2fd4d000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2a2f987000) libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f2a2f749000) /lib64/ld-linux-x86-64.so.2 (0x00007f2a30e87000) libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f2a2f47d000) libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f2a2f24e000) libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f2a2f04a000) libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f2a2ee3e000) libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f2a2ec3a000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2a2ea1b000)

linux-vdso.so。1 = >(0 x00007fffb31fe000)libselinux.so。1 = > /lib/x86_64-linux-gnu / libselinux.so。1 (0x00007f2a309a7000) libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f2a305cd000) libdl.so。2 = > /lib/x86_64-linux-gnu / libdl.so。2(0 x00007f2a303c8000)libz.so。1 = > /lib/x86_64-linux-gnu / libz.so。1(0 x00007f2a301af000)libresolv.so。2 = > /lib/x86_64-linux-gnu / libresolv.so。2(0 x00007f2a2ff94000)libgssapi_krb5.so。2 = > /usr/lib/x86_64-linux-gnu / libgssapi_krb5.so。2(0 x00007f2a2fd4d000)libc.so。6 = > /lib/x86_64-linux-gnu / libc.so。6(0 x00007f2a2f987000)libpcre.so。3 = > /lib/x86_64-linux-gnu / libpcre.so。3(0 x00007f2a2f749000)/ lib64 / ld - linux - x86 - 64.。2(0 x00007f2a30e87000)libkrb5.so。3 = > /usr/lib/x86_64-linux-gnu / libkrb5.so。3(0 x00007f2a2f47d000)libk5crypto.so。3 = > /usr/lib/x86_64-linux-gnu / libk5crypto.so。3(0 x00007f2a2f24e000)libcom_err.so。2 = > /lib/x86_64-linux-gnu / libcom_err.so。2(0 x00007f2a2f04a000)libkrb5support.so。0 = > /usr/lib/x86_64-linux-gnu / libkrb5support.so。0(0 x00007f2a2ee3e000)libkeyutils.so。1 = > /lib/x86_64-linux-gnu / libkeyutils.so。1(0 x00007f2a2ec3a000)libpthread.so。0 = > /lib/x86_64-linux-gnu / libpthread.so。0(0 x00007f2a2ea1b000)

but doing the same in Mathematica:

但是在Mathematica做同样的事情:

RunProcess[$SystemShell, All, " ldd /usr/bin/ssh exit "]

RunProcess[$SystemShell, All, " ldd /usr/bin/ssh出口"]

gives a different dependence on:

给予不同的依赖:

libcrypto.so.1.0.0 => /usr/local/Wolfram/Mathematica/10.0/SystemFiles/Libraries/Linux-x86-64/libcrypto.so.1.0.0 (0x00007f30fbe3c000) libz.so.1 => /usr/local/Wolfram/Mathematica/10.0/SystemFiles/Libraries/Linux-x86-64/libz.so.1 (0x00007f30fba20000)

libcrypto.so.1.0.0 => /usr/ local/wolfram/mathematica /10.0/SystemFiles/Libraries/Linux-x86-64/ lib.so.1.0.0 (0x00007f30fbe3c000) libzso。1 = > /usr/local/Wolfram/Mathematica / 10.0 / SystemFiles /图书馆/ linux - x86 - 64 / libz.so。1(0 x00007f30fba20000)

My solution was to replace the file /usr/local/Wolfram/Mathematica/10.0/SystemFiles/Libraries/Linux-x86-64/libcrypto.so.1.0.0 with /lib/x86_64-linux-gnu/libcrypto.so.1.0

我的解决方案是将文件/usr/ local/wolfram/mathematica /10.0/SystemFiles/Libraries/Linux-x86-64/libcrypto.so.1.0.0替换为/lib/x86_64-linux-gnu/libcrypto.so.1.0

this is probably not the best way, but works.

这可能不是最好的方法,但确实有效。

#3


0  

An interesting example / possible solution. When I try to run ffmpeg from MMa (11.3, Ubuntu 17)

一个有趣的例子/可能的解决方案。当我尝试从MMa运行ffmpeg时(11.3,Ubuntu 17)

In[16]:= RunProcess["ffmpeg"]
Out[16]= <|ExitCode->1,StandardOutput->,StandardError->/usr/bin/ffmpeg: /usr/local/Wolfram/Mathematica/11.3/SystemFiles/Libraries/Linux-x86-64/libz.so.1: version `ZLIB_1.2.9' not found (required by /usr/lib/x86_64-linux-gnu/libpng16.so.16)|>

it's trying to use the libz.so from the Mathematica path (as observed by @Łukasz above). Simply running with an empty ProcessEnvironment works?!

它试图使用libz。因此,从数学路径(如上@Łukasz观察到)。使用一个空的ProcessEnvironment简单地运行可以吗?

In[17]:= RunProcess["ffmpeg",ProcessEnvironment-><||>]
Out[17]= <|ExitCode -> 1, StandardOutput -> , StandardError ->
 ffmpeg version 3.3.4-2 Copyright (c) 2000-2017 the FFmpeg developers                                                          built with gcc 7 (Ubuntu 7.2.0-8ubuntu2)

which is nice/interesting.

这是好/有趣。

#1


0  

Łukasz Gładczuk suggestion should work, but there is a better way to accomplish this.

Łukasz Gładczuk建议应该工作,但是有一个更好的方法来完成这项工作。

RunProcess provides a ProcessEnvironment option that allows you to set environment variables for your process. The default value is Inherited, which means the environment variables are inherited from Wolfram Language, which is what is causing library problems.

RunProcess提供了一个ProcessEnvironment选项,允许您为流程设置环境变量。默认值是继承的,这意味着环境变量是从Wolfram语言继承的,这正是导致库问题的原因。

Run echo $PATH in a terminal to find your path, then use:

在终端中运行echo $PATH查找路径,然后使用:

RunProcess[{"ssh", "user@server"}, ProcessEnvironment -> <|"PATH" -> yourpath|>]

where yourpath is your path, as a string.

你的路径就是你的路径,就像一条线。

#2


2  

I found that Mathematica forces library dependencies. If I use ldd /usr/bin/ssh command in terminal I obtain following output:

我发现Mathematica强制图书馆依赖。如果我在终端使用ldd /usr/bin/ssh命令,我会得到以下输出:

linux-vdso.so.1 => (0x00007fffb31fe000) libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f2a309a7000) libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f2a305cd000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f2a303c8000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f2a301af000) libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f2a2ff94000) libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f2a2fd4d000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2a2f987000) libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f2a2f749000) /lib64/ld-linux-x86-64.so.2 (0x00007f2a30e87000) libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f2a2f47d000) libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f2a2f24e000) libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f2a2f04a000) libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f2a2ee3e000) libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f2a2ec3a000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2a2ea1b000)

linux-vdso.so。1 = >(0 x00007fffb31fe000)libselinux.so。1 = > /lib/x86_64-linux-gnu / libselinux.so。1 (0x00007f2a309a7000) libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f2a305cd000) libdl.so。2 = > /lib/x86_64-linux-gnu / libdl.so。2(0 x00007f2a303c8000)libz.so。1 = > /lib/x86_64-linux-gnu / libz.so。1(0 x00007f2a301af000)libresolv.so。2 = > /lib/x86_64-linux-gnu / libresolv.so。2(0 x00007f2a2ff94000)libgssapi_krb5.so。2 = > /usr/lib/x86_64-linux-gnu / libgssapi_krb5.so。2(0 x00007f2a2fd4d000)libc.so。6 = > /lib/x86_64-linux-gnu / libc.so。6(0 x00007f2a2f987000)libpcre.so。3 = > /lib/x86_64-linux-gnu / libpcre.so。3(0 x00007f2a2f749000)/ lib64 / ld - linux - x86 - 64.。2(0 x00007f2a30e87000)libkrb5.so。3 = > /usr/lib/x86_64-linux-gnu / libkrb5.so。3(0 x00007f2a2f47d000)libk5crypto.so。3 = > /usr/lib/x86_64-linux-gnu / libk5crypto.so。3(0 x00007f2a2f24e000)libcom_err.so。2 = > /lib/x86_64-linux-gnu / libcom_err.so。2(0 x00007f2a2f04a000)libkrb5support.so。0 = > /usr/lib/x86_64-linux-gnu / libkrb5support.so。0(0 x00007f2a2ee3e000)libkeyutils.so。1 = > /lib/x86_64-linux-gnu / libkeyutils.so。1(0 x00007f2a2ec3a000)libpthread.so。0 = > /lib/x86_64-linux-gnu / libpthread.so。0(0 x00007f2a2ea1b000)

but doing the same in Mathematica:

但是在Mathematica做同样的事情:

RunProcess[$SystemShell, All, " ldd /usr/bin/ssh exit "]

RunProcess[$SystemShell, All, " ldd /usr/bin/ssh出口"]

gives a different dependence on:

给予不同的依赖:

libcrypto.so.1.0.0 => /usr/local/Wolfram/Mathematica/10.0/SystemFiles/Libraries/Linux-x86-64/libcrypto.so.1.0.0 (0x00007f30fbe3c000) libz.so.1 => /usr/local/Wolfram/Mathematica/10.0/SystemFiles/Libraries/Linux-x86-64/libz.so.1 (0x00007f30fba20000)

libcrypto.so.1.0.0 => /usr/ local/wolfram/mathematica /10.0/SystemFiles/Libraries/Linux-x86-64/ lib.so.1.0.0 (0x00007f30fbe3c000) libzso。1 = > /usr/local/Wolfram/Mathematica / 10.0 / SystemFiles /图书馆/ linux - x86 - 64 / libz.so。1(0 x00007f30fba20000)

My solution was to replace the file /usr/local/Wolfram/Mathematica/10.0/SystemFiles/Libraries/Linux-x86-64/libcrypto.so.1.0.0 with /lib/x86_64-linux-gnu/libcrypto.so.1.0

我的解决方案是将文件/usr/ local/wolfram/mathematica /10.0/SystemFiles/Libraries/Linux-x86-64/libcrypto.so.1.0.0替换为/lib/x86_64-linux-gnu/libcrypto.so.1.0

this is probably not the best way, but works.

这可能不是最好的方法,但确实有效。

#3


0  

An interesting example / possible solution. When I try to run ffmpeg from MMa (11.3, Ubuntu 17)

一个有趣的例子/可能的解决方案。当我尝试从MMa运行ffmpeg时(11.3,Ubuntu 17)

In[16]:= RunProcess["ffmpeg"]
Out[16]= <|ExitCode->1,StandardOutput->,StandardError->/usr/bin/ffmpeg: /usr/local/Wolfram/Mathematica/11.3/SystemFiles/Libraries/Linux-x86-64/libz.so.1: version `ZLIB_1.2.9' not found (required by /usr/lib/x86_64-linux-gnu/libpng16.so.16)|>

it's trying to use the libz.so from the Mathematica path (as observed by @Łukasz above). Simply running with an empty ProcessEnvironment works?!

它试图使用libz。因此,从数学路径(如上@Łukasz观察到)。使用一个空的ProcessEnvironment简单地运行可以吗?

In[17]:= RunProcess["ffmpeg",ProcessEnvironment-><||>]
Out[17]= <|ExitCode -> 1, StandardOutput -> , StandardError ->
 ffmpeg version 3.3.4-2 Copyright (c) 2000-2017 the FFmpeg developers                                                          built with gcc 7 (Ubuntu 7.2.0-8ubuntu2)

which is nice/interesting.

这是好/有趣。