INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Problem with executing ssh in JSP

Problem with executing ssh in JSP

(OP)
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.

RE: Problem with executing ssh in JSP

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

Cheers,
Dian

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close