0

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.

2
  • Question is not clear. Is the intention to obtain the shell script from a remote place and run it locally, or to run a remote shell script on a remote host? Commented Jul 23, 2012 at 3:32
  • the intention is to run the shell script on a remote host! Commented Jul 23, 2012 at 20:32

2 Answers 2

1

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).

Sign up to request clarification or add additional context in comments.

1 Comment

Right in the money. Doing exec delegates effort on OS access to such shared resource and, if the user running the java application does not have rights to execute it, it won't happen
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.