Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Help needed to run unix command on remote machine.

Reply
Thread Tools

Help needed to run unix command on remote machine.

 
 
ruds
Guest
Posts: n/a
 
      09-06-2006
Hello,
can some one tell me how do i run unix commands on unix machine
remotely?
I want to fire a unix command from one my machine onto other machine
through java program.
On shell we use rsh command but it does not work through java, is there
some other way of doing it?

 
Reply With Quote
 
 
 
 
hiwa
Guest
Posts: n/a
 
      09-06-2006

ruds のメッセージ:

> Hello,
> can some one tell me how do i run unix commands on unix machine
> remotely?
> I want to fire a unix command from one my machine onto other machine
> through java program.
> On shell we use rsh command but it does not work through java, is there
> some other way of doing it?


> we use rsh command but it does not work through java

Why?

 
Reply With Quote
 
 
 
 
ruds
Guest
Posts: n/a
 
      09-06-2006

I want to create an application that invokes some other applications on
the unix m/c ,
for this i need to find out the how do i invoke the required
application along with some parameters to it.
And i want this for unix so how do i go about it?

 
Reply With Quote
 
hiwa
Guest
Posts: n/a
 
      09-06-2006
ruds のメッセージ:

> I want to create an application that invokes some other applications on
> the unix m/c ,
> for this i need to find out the how do i invoke the required
> application along with some parameters to it.
> And i want this for unix so how do i go about it?

You could use Runtime.exec() method for running shell command.

 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      09-06-2006
On 5 Sep 2006 21:03:51 -0700, ruds wrote:
> On shell we use rsh command but it does not work through java, is
> there some other way of doing it?


rsh (or better: ssh) should work just fine from Runtime.exec(). What
problems are you having? What does your code look like?

/gordon

--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
Simon
Guest
Posts: n/a
 
      09-06-2006
ruds wrote:

> can some one tell me how do i run unix commands on unix machine
> remotely?


If, for some reason, you find it unconvenient to call ssh from Runtime.exec you
can also use a Java ssh implementation, e.g. this one:

http://www.jcraft.com/jsch/

Cheers,
Simon
 
Reply With Quote
 
ruds
Guest
Posts: n/a
 
      09-06-2006
I want to get cpu stats of the remote machine ,for this i'm using:
Process p=Runtime.getRuntime('rsh mac01 "iostat -t 5"');
but it is not recognizing the rsh and giving error as given in my first
post.

Please tell me what to do?

 
Reply With Quote
 
Simon
Guest
Posts: n/a
 
      09-06-2006
ruds wrote:
> I want to get cpu stats of the remote machine ,for this i'm using:
> Process p=Runtime.getRuntime('rsh mac01 "iostat -t 5"');


Did you try to compile that?

> but it is not recognizing the rsh and giving error as given in my first
> post.


Which error? Which post?

> Please tell me what to do?


Show us the code that you are actually using together with the error message.
 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      09-06-2006
On 6 Sep 2006 01:49:11 -0700, ruds wrote:
> I want to get cpu stats of the remote machine ,for this i'm using:
> Process p=Runtime.getRuntime('rsh mac01 "iostat -t 5"');
> but it is not recognizing the rsh and giving error as given in my first
> post.


None of your posts in this thread say what the error is.

The line of code in your example here will not compile (for more than
one reason). Please post the *real* code you need help with, and the
*real* error messages you get. Use cut-and-paste.

If rsh is not recognized, then you likely need to specify a complete
path like /bin/rsh or /usr/bin/rsh.

Note that if you need to use quoting in the command line, you need to
use the version of exec() that takes an array of Strings. Don't add
any extra quotation marks, the grouping is implied by the array
structure, like this:

String[] cmd = {
"/usr/bin/rsh",
"mac01",
"iostat -t 5",
};

Process p = Runtime.getRuntime().exec(cmd);

/gordon

--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
ruds
Guest
Posts: n/a
 
      09-08-2006
Thanks everyone for replying and Sorry for not posting the code.
Heres the code :

Process p = Runtime.getRuntime().exec("rsh mac5 ps");
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));

BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));

// read the output from the command
System.out.println("Here is the standard output of the command:
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}

// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if
any):\n");
while ((s = stdError.readLine()) != null)
{
System.out.println(s);
}

System.exit(0);
}//end of try
catch (IOException e)
{
System.out.println("exception occured");
e.printStackTrace();
System.exit(-1);
}

I'm able to execute rsh but i'm not getting the $ prompt .
Also ps does not execute properly its giving o/p as:
PID TTY TIME CMD

Thats it.
Can u tell what is the problem and where i'm going wrong???
thanks in advance.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run UNIX command Pieter Jongsma Ruby 3 09-11-2007 07:52 PM
how to run os.execv() to run command pslq dbname < gen.command Sonu Python 2 08-04-2007 11:25 PM
Run Unix shell command $ parse command line arguments in python rkoida@yahoo.com Python 4 04-23-2005 04:42 AM
can I run unix shell command in the ModelSim shell? clinton__bill@hotmail.com VHDL 2 02-18-2005 10:04 PM
Remote Assistance fails to connect, remote remote host name could not be resolved Peter Sale Wireless Networking 1 12-11-2004 09:09 PM



Advertisments