tags:

views:

33

answers:

3

I have two Linux Machine,1st is machine X ,other is machine Y i want to write a java program which will run in machine X..eq test.java ..and when i run that java program it should ask for login credential of machine Y and will execute some command for example ls -l in machine Y automatically after login. and it should display the output of ls -l in machine X. How to do it please help me????

+1  A: 

No need to write a program, use ssh. This will of course require that a ssh server is running on machine Y, but you will need some kind of server to implement this anyway.

unwind
+1  A: 

Why use java for this. This can be easily done by using SSH i.e.

$ssh user@server <command>

If you are running this command on machine X

[user@X~]$ ssh user@Y 'ls -l'
password:

total 16
drwxr-xr-x 2 user group 4096 Apr 13 21:19 fooo
drwxr-xr-x 3 user group 4096 Jun 17  2009 bar
Space
ya you are corect but how ..to display the output of machine Y in machine X...plz tell me??
Rahul
I have edited my answer. If you run this command on machine X and ssh to machine Y, it will display the output on machine X only.
Space
Also, don't forgot to accept the answer which works for you. It will motivate other peoples to provide you better solutions.
Space
A: 

I personally like xmlrpc client/server relationship, can make things a little easier if this is going to scale significantly.

http://www.ibm.com/developerworks/xml/library/j-xmlrpc.html

for an example.

wom