大网数据广告活动
服务器运维问答

Server A tells server B to execute shell script - simplest way?

· 52CE 我爱测

The question I have is vague, but it's vague on purpose because I don't want to bias the answers toward a needlessly specific solution. Let's say I have Linux servers A and B, where server A has a web application on it and server…

问题原文

原帖链接 · Jason Swett · CC BY-SA 4.0

The question I have is vague, but it's vague on purpose because I don't want to bias the answers toward a needlessly specific solution.

Let's say I have Linux servers A and B, where server A has a web application on it and server B doesn't.

Let's say I want server A to tell server B to execute a certain set of shell commands. Because I imagine someone will ask, let's say that the commands I want to run are:

mkdir /var/www/git/repo-1.git
cd /var/www/git/repo-1.git
git --bare init

What's the simplest way I could get server A to tell server B to execute these commands?

FWIW, security IS an important factor in whatever solution I use.

已采纳解答

原帖链接 · v25 · CC BY-SA 4.0

You didn't specifically mention that the commands are to be invoked from the web-app, so I'll assume that's not the case, as this would make the question more 'solution specific'.

The simplest method, assuming you have ssh access.

Do this on the terminal of serverA:

$ cat > script.sh                 
cat /proc/sys/kernel/hostname
^C

$ scp script.sh serverB:~
script.sh    100%   31     9.8KB/s   00:00

$ ssh serverB 'sh ~/script.sh'
serverB

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-10-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。