aspose file tools*
The moose likes I/O and Streams and the fly likes JSP page to call unix scrpit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "JSP page to call unix scrpit" Watch "JSP page to call unix scrpit" New topic
Author

JSP page to call unix scrpit

akki gupta
Greenhorn

Joined: Nov 01, 2011
Posts: 9
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

Joined: Jul 06, 2005
Posts: 1016
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

Joined: Jan 10, 2002
Posts: 60077
    
  65

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP page to call unix scrpit
 
Similar Threads
Error while accessing hibernate session through JSF
appending dynamic data in the jsp
Problems getting a JSP to act as proxy
Insert new records in database without deleting existing records
How to connect to Linux using Java code?