1

I'm currently using java.lang.ProcessBuilder to run a shell script on the local machine.

Now I want to use it to run the shell script on different machines. How do I do that?

Note: These are all Linux machines, and I specifically want to use ProcessBuilder to do it.

ruakh
  • 175,680
  • 26
  • 273
  • 307
  • For security reasons, it's not possible for arbitrary computers on the Internet to run arbitrary shell scripts on arbitrary other computers on the Internet. So either you're leaving out a lot of details (like -- how these machines are related to each other and how they know to accept shell scripts from each other), or what you're asking for is impossible. – ruakh Feb 15 '19 at 06:11
  • using com.jcraft.jsch.JSch library you can connect to different remote machines for that you need remote machine credentials and https://stackoverflow.com/questions/995944/ssh-library-for-java/996415#996415 – Akash Shah Feb 15 '19 at 06:31

2 Answers2

0

Java doesn't support running code on remote host directly.

You have few option here:

  • create script which will use ssh or telnet to run script on remote host.
  • use some ssh library,
talex
  • 17,973
  • 3
  • 29
  • 66
0

Java doesn't support running code on remote host directly.

You can write a process builder application and deploy it to the destination machine, that listens on some port 'X', from the source system, you can send the commands to the port 'X' of destination system, let the process builder application execute the command on destination machine.

Hari Krishna
  • 3,658
  • 1
  • 36
  • 57