-1

Have a problem in running unix code in jsp page, my jsp code is as below.

<%@page language="java" %>

<%@page import="java.util.*" %>

<html>

<head>

<%
    String unixCommand = "/bin/bash -lc \"/home/chandu/test/./check.sh xxxxxx\"";

     Runtime rt = Runtime.getRuntime();

     rt.exec(unixCommand);
    System.out.println("Print Test Line.");

%>

</head>

<body>

</body>

</html>

Unix code is below

!/bin/bash -l

cd /home/chandu/test/ for i in cat nodelist do java -cp /home/chandu/test jcmd "$i" ZMIO:MSISDN=$1: > "$i".log done vlradd=grep MSC-ADDRESS *.log | awk '{print $4}' mss=grep $vlradd mss | awk '{print $1}' java -cp /home/chandu/test jcmd "$mss" ZMVO:MSISDN=$1: | egrep "LOCATION AREA CODE OF IMSI|LAST USED CELL ID" | cut -d "/" -f2 > output lac=head -1 output | tail -1 cellid=head -2 output | tail -1 echo $lac $cellid You have new mail in /var/mail/root

Community
  • 1
  • 1

1 Answers1

0

You need to

  1. collect the standard out/err from the Unix process and write into your JSP.
  2. use Process.waitFor() to wait for the process exist and collection the return code. Otherwise you'll have a zombie process.

You need to read from the streams provided by the Process object returned by rt.exec() to capture the output. See this SO answer for more details.

Community
  • 1
  • 1
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440