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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KuldeepchaturvediCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.