Use jsp pages to connect to a UNIX server

Hi

I need to create a solution wherein a jsp site talks to applications running on UNIX server. For starters lets say - a jsp request sent to check the status of any UNIX process by running a 'ps' command on UNIX. I would like to get the result of the 'ps' command and should be able to display the same on the web.

I am pretty new to the jsp domain - please suggest a solution ASAP and in a very basic fashion.

Any pointers to articles, tutorials, books online will also be appreciated.

Thanks in advance.

sushiltanna
sushiltannaAsked:
Who is Participating?
 
KuldeepchaturvediConnect With a Mentor Commented:
you can use System.runtime to run the process on the unix server..
pre-requesite is that your jsp shd be running on that same server....
code sniplett will look something like..
<%
  String ls_str;

          Process ls_proc = Runtime.getRuntime().exec("/bin/ls -aFl");

          // get its output (your input) stream

          DataInputStream ls_in = new DataInputStream(
                                          ls_proc.getInputStream());

          try {
            while ((ls_str = ls_in.readLine()) != null) {
               out.print(ls_str);
            }
          } catch (IOException e) {
System.err.println(e1);

                }
      } catch (IOException e1) {
          System.err.println(e1);
                }
0
 
koppchaCommented:
One more example

<%          
          try
          {
          Runtime runTime = Runtime.getRuntime();
          Process process = runTime.exec ("/bin/ps");
          InputStream inputStream = process.getInputStream();
          InputStreamReader   inputStreamReader = new InputStreamReader (inputStream);
          BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
          String line = null;
         while ( (line = bufferedReader.readLine()) != null )
         out.println(line);
         int exitVal = process.waitFor();
         out.println ("Process exitValue:  " + exitVal );
          }
          catch (Throwable t)
          {
               t.printStackTrace();
          }
%>

In the above code bufferedReader.readLine() will read all the lines that are printed by the 'ps' command and print on the page.process.waitFor() will return the exit value of the command.


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.