• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Execution of commands on remote machine.

 
Shivam Choubey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a requirment in which we need to execute command on a remote machine.
Do any one know how to do in a simplest way.
We are short of time so code snippents will work wonders .

Thanks & regards,
Shivam
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Shivam Choubey ,

Welcome to JavaRanch

Though it is impossible to give the complete code snippet, an idea can very well be given as the implementation is left to you and the language you choose.

One idea is you can pass the command from your machine to the remote host and get the command executed in the remote machine. Socket Programming is the best rescue for the same.

Any other easy way ??
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the remote machine is a Unix machine with a running SSH daemon you can use SSH to execute the command. There are enough Java SSH solutions around the Internet, Google can help you with those.

If it's a Windows machine perhaps RPC or something similar can help you, but that's outside my scope of knowledge.


Raghavan: a Socket can help you if you have your own program / service running on the remote machine with a ServerSocket listening for requests, but otherwise you would need to connect with another service that allows command execution. There aren't many of those.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:


Raghavan: a Socket can help you if you have your own program / service running on the remote machine with a ServerSocket listening for requests, but otherwise you would need to connect with another service that allows command execution. There aren't many of those.


Thank you Rob. Yes, SSH is indeed a good option. Somehow I missed it

As you said, "There aren't many of those" -- the default option was of Sockets!
 
Shivam Choubey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Raghav & Rob for helping... I will check with it.

Regards,
Shivam
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raghavan Muthu:
As you said, "There aren't many of those" -- the default option was of Sockets!

But with a Socket you can only connect to a listening server socket, and the application in which that server socket is running must support the protocol: reading a command, then executing that.

The SSH daemon is one such applcation (given the right parameters), but its protocol has some more caveats. That's why a simple Socket won't do. A Java SSH library will probably use Sockets in the background, but with a lot of extra code added.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:

But with a Socket you can only connect to a listening server socket, and the application in which that server socket is running must support the protocol: reading a command, then executing that.



True. I meant you get connected to a listening socket and pass the commands to the socket as data. The listening socket then has to delegate this passed command and get it executed in its native OS and in turn returns back the actual result of the command from the OS.

If my understanding is right, this is what generally happens behind the scenes even in case of SSH.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are short of time, it would probably help to provide more information (what systems are we talking about, how are they connected, what commands do you need to execute and why, how much control do you have over those systems etc. pp.) so that we can be more effective helping you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic