Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem usign rsh from runtime.exec

Status
Not open for further replies.

sourabhjha

Programmer
Jan 13, 2002
121
IN
Hi ,
I am having strange issue while using the rsh command to invoke remote commnad on a unix host from a java pgm.

the code is simple.

Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec(remoteCommandString);

Now here the string "remoteCommandString" is formed while reading some properties file.
Before running the command using runtime.exec() i am even displaying the whole string to make sure there are no syntax errors.

here is what it displays before getting executed
rsh gpseai01.corporate.ge.com -l jhaso "/home/getdata.sh"

I get some error like this
ksh: /home/getdata.sh : not found

However in the code if i just form the remoteCommandString by hardcoding the full command like this
String remoteCommandString= "rsh gpseai01.corporate.ge.com -l jhaso" +" \""+ "/homegetdata.sh"+"\"";

It goes just fine and i get the proper result.

I was wondering what diff it makes causing the command to fail in first case.
Please let me know if anyone has any ideas.

Thanks,
-Sourabh
 
I assume that the difference

/home/getdata.sh

and

/homegetdata.sh

is a typo and not true in your code, right?
 
yes thats a typo.rwad "/homegetdata.sh" as "/home/getdata.sh
 
Is the missing space after jhaso also a typo?

Try this: build the command string from the property file, then just before calling exec build a second hardcoded command string and do an equals() on them.

If they are not equal, you should be able to print them both to println.out and spot the difference.

If they ARE equal, then one working and one not is just a coincidence. Look for another possible cause.
 
Still the problem.

Here is the piece of code where i form the strings

String remoteCommandStringnew= "rsh gpseai02.corporate.ge.com -l jhaso" +" \""+ "/export/home/jhaso/getdata.sh /eai02/e001,/dev/vx/dsk/var"+"\"";
String remoteCommandString = "rsh " + hostName.trim() + " -l "+ loginprops.getProperty("LOGIN").trim()+ " \"" + loginprops.getProperty("SHELLFILE_PATH").trim()+fileSystems+ "\"";


And here is the output of the pgm when i run that to compare
wmadm@scheai09 #
Static String :rsh gpseai02.corporate.ge.com -l jhaso "/export/home/jhaso/getdata.sh /eai02/e001,/dev/vx/dsk/var"
From props file:rsh gpseai02.corporate.ge.com -l jhaso "/export/home/jhaso/getdata.sh /eai02/e001,/dev/vx/dsk/var"
Are They Equal? true


Same command i just copy paste from the pgm output and run from command line ,goes fine.
One thing which i have noticed is that when i run it without passing the parameters to getdata.sh then it goes fine from the pgm.When i add the parameters to the getdata.sh then it is failing.The error essage indicates it is some syntaxe error.Here is what i get as error message when i run this pgm to execute the remote command.

wmadm@scheai09 # java GetEAIHostsStatus
From prgm - command is: rsh gpseai01.corporate.ge.com -l jhaso "/export/home/jhaso/getdata.sh"
CPU_USAGE=59
CPU_LOAD= 5.55
SPACE_USAGE=
From prgm - command is: rsh gpseai02.corporate.ge.com -l jhaso "/export/home/jhaso/getdata.sh /eai02/e001,/dev/v
x/dsk/var"
ksh: /export/home/jhaso/getdata.sh /eai02/e001,/dev/vx/dsk/var: not found


As u can see i run the pgm in loop to fire rsh twice.First for the remote host gpseai01.It goes fine.Next run for gpseai02.It fails as i pass parameters(eai02/e001,/dev/vx/dsk/var) to the getdata.sh.\
Purpose of getdata.sh retunrs the CPU data from the remote machine.

-Sourabh
 
problem resolved.some syntax issue on unix.the sequemce of parameters for rsh was not correct.
Thanks for you time.
-sourabh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top