• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to execute commands on remote machine

 
Harish Tiruvile
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI all,

Qusteion:
Is it possible to write an application which will execute commands on remote machine...like restating tomcat server

Now i want to execute command on remote machine , so

1. password authentication
2.restarting server(if authenticated)


By using java Runtime class i can execute commands on local machines...Is it possible to excute commands and process the result on remote machine?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. All you need is a program running on the remote machine listening for commands to execute, and a way to communicate with that program. Lots of UNIX machines already have such a program running: it's called sshd. I suppose lots of Windows machines have such a program too; it's called Internet Explorer (baboom BOOM kish! Thanks folks, don't forget to tip your waitress!)
 
Harish Tiruvile
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ernest Friedman-Hill ,

Can you please tell me How to proceed..i mean which class in java provide SSH connection..is it possible to do that using Runtime class..if you have any link please post that site here
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your servers are already running ssh, and you'll have ssh access, then there are a lot of Java SSH libraries out there to choose from.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Sure. All you need is a program running on the remote machine listening for commands to execute, and a way to communicate with that program. Lots of UNIX machines already have such a program running: it's called sshd. I suppose lots of Windows machines have such a program too; it's called Internet Explorer (baboom BOOM kish! Thanks folks, don't forget to tip your waitress!)


Nice one
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's specifically Tomcat you want to control from afar, then you can do that via a number of Ant tasks that support that. Here is some documentation about that.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Sure. All you need is a program running on the remote machine listening for commands to execute, and a way to communicate with that program. Lots of UNIX machines already have such a program running: it's called sshd. I suppose lots of Windows machines have such a program too; it's called Internet Explorer (baboom BOOM kish! Thanks folks, don't forget to tip your waitress!)




The documented way to do it would be to use Windows Scripting Host ability to call remote scripts.
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Start with Server Sockets & Normal Sockets ... seems you may require RAW Sockets too. First try to develop the server socket on local machine and make sure that it is working fine then port this to remote machine and try.

1) The server socket will get the request from remote client and will perform the operation and will return back the result.

2) Remote java program will process the data and will show to the end user.

If you want to protect the data then use any wrapper over socket.

All the best
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Srinivas Kalvala:

Start with Server Sockets & Normal Sockets ... seems you may require RAW Sockets too.


No; sorry, but this is a terrible idea. If he's going to roll his own solution, better to use either HTTP(S) or RMI. It would silly to start absolutely from scratch for this -- what would be the point?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
If it's specifically Tomcat you want to control from afar, then you can do that via a number of Ant tasks that support that.


You can, although this mechanism falls down if (when) you need to restart an utterly frozen Tomcat -- which does happen -- because it uses Tomcat's built-in admin server. If you're local, you can kill it and restart it.
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:


It would silly to start absolutely from scratch for this -- what would be the point?



Sorry, I did not get your point and I dont think it as writing from scratch. Already java sockets are providing enough abstraction. Do you want to use any other specific wrapper over Socket for this operation?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Srinivas Kalvala:
Do you want to use any other specific wrapper over Socket for this operation?


Did you read any of the other posts in this thread (about ssh, or wsh?) or even the post you're responding to (about RMI or HTTPS?)
 
Robert Hill
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think a good(ie more flexible) solution would be to implement the telnet protocol(RFC 854) and add in ssh. Something similar to the open source program putty. http://www.chiark.greenend.org.uk/~sgtatham/putty/

It would work for starting tomcat and any other program on the remote system, provided you have permission to do so of course.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This stuff was invented before I was born and here we are reinventing it - perhaps for good reason. Do the existing solutions actually target the problem and nothing more? If so, why reinvent since you will have the exact same product at the end? If not, then reinvent it (make the wheel more round). More often than not, I see a reinvention without the requirement leak. In other words, a minimalism of what already exists. This is also an inherent property of Java/OO itself.

Why aren't alarm bells ringing for anyone else? Backus wrote about it the year I was born!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic