使用SSH提交时无法识别R命令

mle*_*gge 0 linux ssh r

我是一个远程主机,反过来提交的R脚本,但错误上提交一个shell脚本R: command not foundRscript: command not found(取决于自己是否尝试过R CMD BATCHRscript).

我尝试过以下方式提交:

 ssh <remote-host> exec $HOME/test_script.sh

 ssh <remote-host> `sh $HOME/test_script.sh`
Run Code Online (Sandbox Code Playgroud)

该脚本test_script.sh包含(已尝试Rscript过):

#!/bin/sh

Rscript --no-save --no-restore $HOME/greetme.R

exit 0
Run Code Online (Sandbox Code Playgroud)

该脚本greetme.R仅包含cat("Hello\n").

我感到慌乱的原因是,当我登录remote-host并提交原始脚本时sh $HOME/test_script.sh,它会按预期运行.

本地和远程主机的系统规格和R版本是相同的:

> R.version
               _                           
platform       x86_64-unknown-linux-gnu    
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          3                           
minor          1.0                         
year           2014                        
month          04                          
day            10                          
svn rev        65387                       
language       R                           
version.string R version 3.1.0 (2014-04-10)
nickname       Spring Dance       
Run Code Online (Sandbox Code Playgroud)

为什么Linux拒绝识别这些命令?

我更喜欢使用的解决方案R CMD BATCH,Rscript但是如果有已知的解决方法使用littler或者%R_TERM%我也希望听到它们.

我使用这个相关的问题作为参考,以及评论中引用的文件:R.exe,Rcmd.exe,Rscript.exe和Rterm.exe:有什么区别?

编辑解决方案:

正如@ merlin2011建议的那样,一旦我指定了完整路径test_script.sh,一切都按预期工作:

#!/bin/sh

/opt/R/bin/Rscript --no-save --no-restore $HOME/greetme.R

exit 0
Run Code Online (Sandbox Code Playgroud)

我也通过提供的建议获得了这条路径:

$ which Rscript
/opt/R/bin/Rscript
Run Code Online (Sandbox Code Playgroud)

mer*_*011 5

您似乎遇到了一个PATH问题,当您尝试运行命令时,该问题R不在您的PATH身上ssh.

如果指定的完整路径R,并Rscript在远程主机上,它应该解决这个问题.

如果您不确定完整路径是什么,请尝试登录服务器并运行which R以获取路径.