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.

  • 1
    use ssh to run the commands remotely. you can use ssh keys for the security, it will be encrypted and you can even restrict commands if required. – olivierg Oct 9 '19 at 19:03
  • security as in, you care that the server A can tell service B to do this and nothing else, or auth as in, you care that only server A can tell it to ? – Sirex Oct 9 '19 at 19:17

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

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

$ ssh serverB 'sh ~/script.sh'
| improve this answer | |

You can simply use SSH. Typically you would use a public/private key pair to allow the master to log into the slave without requiring a password.

Then use

   SSH user@slave.IP  "command"

Note that command can be a single command, a comma separated list of commands or even multiple lines. You can use single quotes for an exact command or double quotes if you will want to interpret variables.

There are many other solutions as well, most either use agents(like puppet or chef) or expand on SSH functionality (like ansible). Depending on your definition of simplest, SSH is probably the best candidate.

| improve this answer | |

simplest way ? if A has a web app on it, make server A have a url server B can query for, like blah.html?shouldidothatthing that returns 'yes' or 'no. then have server B poll for it in a loop.

this avoids auth issues, or needing to restrict what server B can let server A tell it to do, etc. but if you want to pass sensitive info wont work well.

Essentially, don't push between them, pull it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.