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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with executing ssh in JSP

Status
Not open for further replies.

rach18

Programmer
Feb 6, 2009
9
0
0
US
Hi,

I need to run a script(/home/rs/Get_FileList) which is on a remote server(usnav.mh.vntnt.com), as user 'rs'. The script takes 2 arguments: requirements and 16.1. When i try to do this with JSP(code as given below), the following command is returning "null":

rt.exec(command);


JSP code:
=======================================================================================
try
{
Runtime rt = Runtime.getRuntime();
String command = "/opt/bin/ssh rs@usnav.mh.vntnt.com ksh /home/rs/Get_FileList requirements 16.1";
Process proc = rt.exec(command);

InputStream stdin = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stdin);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ( (line = br.readLine()) != null)
out.println(line);
int exitVal = proc.waitFor();
}
catch(Exception e)
{
out.println(e);
e.printStackTrace();
}
catch (Throwable t)
{
=======================================================================================

Note:
* SSH keys are configured for promptless mode.
* When i try to execute the same SSH command from command prompt, it successfully executes:
>opt/bin/ssh rs@usnav.mh.vntnt.com ksh /home/rs/Get_FileList requirements 16.1
* If i try handling stderr in the above code, it says: "Host key verification failed". But even though i remove all keys
using "ssh-keygen -R hostname" and then once again configure SSH keys, it again fails. I checked all the SSH keys in both servers. It is perfect.
* My question is do we need to configure anything else in tomcat? Because the SSH is executed successfully via command prompt and even via the shell script. The problem is only when SSH is used in JSP.


Please let me know your views.

Thanks.

 
Two ideas:
- Test the command directly into OS
- Pass parameters as an array as shown here

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top