My colleague has quit and disappeared suddenly, left us some unfinished webpages that we are totally new to. We think she has won a lottery, big, or something.
Anyway, ideally what we are trying to do is, to let the customer click a button in the web browser, and then the web server to call a shell script to do the work. The output from the stdout && stderr of the script should be displayed in the web browser once finished or timeout, along with the exit code of the script.
The shell script is however not on the web server, but on another app server. So to call this script from the web server as the identity 'tomcat':
$ sh appuser@app-server:\$appbin/app-script
The .ssh/id_rsa.pub thing is done, and we have no problem doing this in the command line so far.
Our loaded ex-colleage has left us the webpages (jsp) with code like these:
<%@ include file="jsp_functions.jsp" %>
String cmd = "sh $appbin/app-script";
ExecResult r = new ExecResult();
int iCode = r.getExitCode();
String result = r.getResult();
<link rel="stylesheet" type="text/css" href="../css/app.css" />
<title> Generate Reports </title>
<h1 id="rpts_h1"> Reports Retrieval </h1>
<textarea rows=35 cols=80 id="result_textarea">
Exit Code: <%=iCode%>
<input type="button" value="Menu" onClick="<%=cancel_back%>">
My questions are:
- How do you do it?
- and why 'sh $appbin/app-script' is sufficient? There is a suspicious jar file named 'ganymed-ssh2-build250.jar' in WEB-INF/lib/ .
- half of the time r.getExitCode() returns NULL, and half returns the expected code. why!?