如何在远程运行shell脚本时解决依赖关系?

kma*_*o23 0 linux ssh bash shell sh

我正在尝试远程运行shell脚本.我在一台机器上有一个资源(.txt文件),在另一台机器上有一个shell脚本,但是在同一个网络中.该脚本驻留在特定目录中,并且该脚本获取一些二进制文件,这些文件驻留在目标计算机中的所有其他目录中.现在,我无法远程运行脚本.但我可以运行一个没有任何本地依赖项的简单shell程序.你能建议一个解决方案来解决这个问题吗?

这是我用来运行shell-script-without-any-dependencies的命令.

cat input.txt | ssh clrg@192.168.2.22  "sh path/to/shell/script/tokenize.sh"  
Run Code Online (Sandbox Code Playgroud)

在运行具有依赖项的脚本时,我收到以下错误,

"ambiguous redirect"  
../../deter-4/bin/determine: No such file or directory  
../../deter-4/bin/determine1: No such file or directory
Run Code Online (Sandbox Code Playgroud)

现在,如何在运行shell脚本时告诉接受依赖项

Alf*_*lfe 5

我认为你的问题是工作目录.尝试这样的事情:

cat input.txt | ssh clrg@192.168.2.22  "sh -c 'cd /path/to/shell/script; ./tokenize.sh'"
Run Code Online (Sandbox Code Playgroud)

您的脚本似乎只能从特定的工作目录运行.您在评论中提到的有关相对路径(从头开始../../)的错误消息至少表明了这一点.

  • `sh -c'......'是不必要的; `ssh`的参数传递给登录shell,因此可以是任意一系列shell命令. (3认同)