简体   繁体   中英

Java application to execute shell files from different servers

I would like to know if the following is possible:

I have to create a Java application that runs .sh files from different servers, I have my class to execute shells, with Runtime and Process, it runs .sh files from my computer, the thing now is that I would like to know if instead of my location be

    process = runtime.exec("/home/user/Documents/example.sh");

could be:

    process = runtime.exec("180.150.2.***/server/user/Documents/serverExample.sh");

and the thing is, that to get the .sh files from server, I have to login, this application could be a desktop application or a web application, but has to be in Java, so, how could I do this?

I appreciate your help.

Chema.

Basically, I don't think you can do that, the way you are trying. The Runtime.exec(...) will delegate to the OS to perform the actual execution.

There are any number of ways to achieve what you want, either purely in Java or via additional utilities based on the OS.

You could SSH or telnet to the remote machine and execute the commands via those interfaces.

You could write a client server app, where the server would allow you to send commands to it to be executed on your behalf (but you must understand that this is a massive security risk).

Check out Jsch or Ganymed SSH . I have used the latter to perform ssh/scp tasks programmatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM