1

I need to access and run Linux commands on a remote CentOS machine through Java code. Please suggest me any API to access run the commands and also I need to get the output of the commands to be printed on the Java console.

Nani
  • 1,148
  • 3
  • 20
  • 35
  • possible duplicate of [Basics - reading/writing remote files using Java](http://stackoverflow.com/questions/12615475/basics-reading-writing-remote-files-using-java) – runDOSrun Feb 08 '15 at 16:52
  • You could use JSCH to call a remote SSH server. – eckes Feb 09 '15 at 04:01
  • @runDOSrun: thanks for responding. I was looking to run command and get it's output from a remote CentOS machine through Java, but in the question U marked duplicated they required to access file system. Please check the details before U mark duplicate – Nani Feb 09 '15 at 06:40

2 Answers2

1

Check out JSch - it allows you to connect via SSH, execute commands remotely and transfer files.

0

You can use Java ProcessorBuilder and Process classes to start an ssh process that executes remote command i.e. start an ssh process (e.g. ssh username@REMOTE_MACHINE 'CMD_ON_REMOTE_MACHINE') and read the output of the executed command using getInputStream() method of Process class.

mohsan
  • 66
  • 4