Two Laptop Bag*
The moose likes Sockets and Internet Protocols and the fly likes Using Java to run shell script on Unix server installed on remote macine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Using Java to run shell script on Unix server installed on remote macine " Watch "Using Java to run shell script on Unix server installed on remote macine " New topic
Author

Using Java to run shell script on Unix server installed on remote macine

Nipun Bahr
Ranch Hand

Joined: Jul 09, 2008
Posts: 55

Hi All,

I want to Use Java to run shell script on Unix server installed on remote macine.

Can you please suggest me the ways to achieve this?

Any ideas/suggestions would be higly appreciated
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Use a Java SSH library like JSch to connect to the remote server. If for some reason you're stuck using Telnet, check out the Apache Commons Net library for a Telnet client. You should NOT use Telnet over a public network, though.
Nipun Bahr
Ranch Hand

Joined: Jul 09, 2008
Posts: 55

Hi Tim,

Thanks for your response.

JSch download is restricted at my place.

Can we do the same using Process Builder?

I need to run a unix script on remote machine by supplying two arguments, please suggest.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Nipun Bahr wrote:
Can we do the same using Process Builder?


Since ProcessBuilder, like Runtime.exec, can only execute processes locally, that will only work if you have a process such as ssh that you can invoke, so you can invoke that process and tell it to run the remote command. For instance, you might be able to to something like


I leave the research on the details of how to make that work up to you, but one caveat I'll give you is that I don't think ssh likes taking passwords from anything other than a terminal. One way around that is to add your public key to the authorized_keys file on the remote host. You can also research those details yourself.
 
 
subject: Using Java to run shell script on Unix server installed on remote macine
 
Similar Threads
Weblogic Server shutting down automatically
FTP
Unix With Java....
Using Java to run shell script on Unix server installed on remote macine
issue when calling shell script from java