Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

shell - 如何使用SSH在远程计算机上运行shell脚本?(How to use SSH to run a shell script on a remote machine?)

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

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

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.

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

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

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

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

(有没有办法使用plink / ssh运行?)

  ask by translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

(如果机器A是Windows框,则可以将Plink( PuTTY的一部分)与-m参数一起使用,它将在远程服务器上执行本地脚本。)

plink root@MachineB -m local_script.sh

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

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

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

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

(您不必将脚本复制到远程服务器以运行它。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...