linux - 使用 ssh 在 shell 脚本中 undefined variable

标签 linux r shell ssh

我使用 shell 脚本运行 R 程序,如下所示:

host_list="server@com" Directory="/home/program/" ssh -f "$host_list" 'cd $Directory && nohup Rscript L_1.R> L_1_sh.txt'

但它总是说

Directory: Undefined variable.

最佳答案

SSH 不会传播所有环境变量。您只是在本地客户端 ssh 程序的环境上进行设置,而不是在服务器端进行设置。作为一种破解,只需将其粘贴到 ssh 远程运行的命令中,而不是预命令环境设置中。

host_list="server@com"  ssh -f "$host_list" 'Directory="/home/program/"; cd "$Directory" && nohup ...'

这是该命令的一个简单版本,您可以在不依赖于特定程序设置的情况下对其进行测试。

ssh localhost Dir="/etc"; echo Dir is "$Dir"; cd "$Dir" && pwd && ps

关于linux - 使用 ssh 在 shell 脚本中 undefined variable ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29814961/

相关文章:

apache - 通过 RApache 安装 R Web 应用程序的最简单方法是什么?

bash - 在bash脚本中执行相对路径可执行文件

shell - Groovy:如何在 groovy 中执行复杂的 shell 命令?

linux - startx 后自动运行脚本

linux - 在不使用 drop_caches 的情况下清除/proc/meminfo 中的 "cached"内存

linux - 用于启动运行单控制台应用程序的 docker 容器的 bash 脚本无法以交互模式发送命令

linux - 将 Parallels Plesk Panel 从版本 9.3.0 升级到 11.0.9(最新版本)

r - 我可以使用 dplyr 对每组不同的大小进行子采样吗?

r - 如何在 R 中保存绘图图像?

linux - bash 脚本需要改进循环通过 12 小时前的目录,删除内部的符号链接(symbolic link)并删除目录