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.
Asked
Active
Viewed 2,116 times
1
-
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 Answers
1
Check out JSch - it allows you to connect via SSH, execute commands remotely and transfer files.

aditsu quit because SE is EVIL
- 4,019
- 1
- 34
- 48
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