Link to home
Start Free TrialLog in
Avatar of sushiltanna
sushiltanna

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Kuldeepchaturvedi
Kuldeepchaturvedi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.