如何使用SSH在远程计算机上运行Shell脚本? [英] How to use SSH to run a shell script on a remote machine?
问题描述
我必须在远程计算机上运行Shell脚本(Windows/Linux).
I have to run a 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?
推荐答案
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屋!