Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Nipun Bahr
Ranch Hand
Posts: 55
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2851
46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic