如何使用SSH在远程机器上运行本地shell脚本? [英] How to use SSH to run a local shell script on a remote machine?

查看:68
本文介绍了如何使用SSH在远程机器上运行本地shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在远程机器上运行本地 shell 脚本(windows/Linux).

I have to run a local shell script (windows/Linux) on a remote machine.

我在机器 A 和 B 上都配置了 SSH.我的脚本在机器 A 上,它将在远程机器 B 上运行我的一些代码.

I have SSH configured on both machine A and B. My script is on machine A which will run some of my code on a remote machine, machine B.

本地和远程计算机可以是基于 Windows 或 Unix 的系统.

The local and remote computers can be either Windows or Unix based system.

有没有办法使用 plink/ssh 运行此操作?

Is there a way to run do this using plink/ssh?

推荐答案

如果 Machine A 是 Windows box,则可以使用 Plink(PuTTY) 和 -m 参数,它将在远程服务器上执行本地脚本.

If Machine A is a Windows box, you can use Plink (part of PuTTY) with the -m parameter, and it will execute the local script on the remote server.

plink root@MachineB -m local_script.sh

如果机器 A 是基于 Unix 的系统,您可以使用:

If Machine A is a Unix-based system, you can use:

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

您不必将脚本复制到远程服务器来运行它.

You shouldn't have to copy the script to the remote server to run it.

这篇关于如何使用SSH在远程机器上运行本地shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆