File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP page to call unix scrpit

 
akki gupta
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I've the following code..

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%@ page import="com.jcraft.jsch.*"%>
<%@ page import="com.jcraft.jsch.Channel.*"%>
<%@ page import="com.jcraft.jsch.Session.*"%>
<%@ page import ="com.jcraft.jsch.UserInfo.*"%>
<%@ page import="java.io.*"%>
<%

String user="arbor";
String host="172.18.104.66";
String cmd="sh /arbordirtux/bin/RECO/Billing_EBPP_reco.sh";
JSch jsch=new JSch();
try
{
Session s=jsch.getSession(user,host,22);
s.setPassword("wipro@345");
//UserInfo usrInfo=new MyUserInfo();

s.connect();
Channel ch=s.openChannel("exec");
((ChannelExec) ch).setCommand(cmd);
ch.setXForwarding(true);
InputStream in = ch.getInputStream();
ch.connect();
ch.setInputStream(System.in);
byte[] tmp = new byte[1024];
while (true)
{
while (in.available() > 0)
{
int i = in.read(tmp, 0, 1024);
if (i < 0)
break;
System.out.print(new String(tmp, 0, i));
}
if (ch.isClosed())
{
in.close();
break;
}
try
{
Thread.sleep(1000);
}
catch (Exception ee)
{

}
}
ch.disconnect();
s.disconnect();
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception"+e);
}


%>

</body>
</html>



what is InputStream in = ch.getInputStream(); doing in this code???
 
Stefan Evans
Bartender
Posts: 1640
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSch is a pure Java implementation of SSH2.
>what is InputStream in = ch.getInputStream(); doing in this code???
At a guess it would be getting an input stream from the channel so that you can send input/commands to the remote ssh session you have connected to.

I don't know what you are trying to accomplish, but I am 100% certain that nothing related to this code belongs in a JSP.


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64180
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:I don't know what you are trying to accomplish, but I am 100% certain that nothing related to this code belongs in a JSP.

Absolutely. I'm thoroughly and definitely convinced that JSP is the number one misused technology in the entire Java stack.

In any case, this has nothing at all to do with JSP so it's been moved to a more appropriate location.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic