bash - 通过 SSH 执行存储在文件中的 Bash 脚本

标签 bash ssh

假设我在文件 foo.sh 中存储了以下 Bash 脚本:

#!/bin/bash
echo foo

无需 scp 文件,我如何才能在远程计算机上执行存储在 foo.sh 中的脚本?

我尝试了以下(有一些变化)但没有成功:

$ ssh root@remote eval `cat foo.sh`

eval `cat foo.sh`似乎在此处扩展为 eval #!/bin/bash echo foo

最佳答案

ssh root@MachineB 'bash -s' < local_script.sh

我从那个线程得到它:How to use SSH to run a shell script on a remote machine?

关于bash - 通过 SSH 执行存储在文件中的 Bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5663679/

相关文章:

Python inside bash 输入错误

string - 在 bash 中提取字符串的前两个单词

shell - 使用expect、ssh、ant和mysqldump时正确转义引号和括号

linux - 通过非标准 ssh 端口使用 Chef & Amazon

git - 命令 git ls-remote 在 Bitbucket 上超时,git clone 工作

java - 在 OS X 上启动终端并使用 Java 运行命令

linux - 仅当文件未设置为可执行文件时才需要在当前目录中运行命令

bash - jenkins管道在循环中执行ssh命令

linux - svn 导出在命令行上工作,但在 shell 脚本中不工作

perl - 有时长时间运行的 ssh 命令会停止打印到标准输出