File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes web interface to a linux server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "web interface to a linux server" Watch "web interface to a linux server" New topic
Author

web interface to a linux server

Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
I am supposed to develop a web interface to interact with a linux server and modify one config file and execute certain command lines. I am going to use JF for the front end. There are no database business involved. Main thing would be in running some command lines and checking the log file to proceed to the next command line.

I may also have to access more than one server depending upon the user selection.

host name: XXXX
username : dummy
port no: 22


Can anyone give an outline picture on how to achieve this? Thanks in advance.
Regards
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Hi Gopu,

it's relatively easy to run a Linux command on the command line of a remote machine via SSH. You could do this simply on the OS layer, preferable with public key authentication. Of course this is only possible if you are allowed to do some configuration to the Linux machines, though it's really a small change to make.

If you are able to establish "transparent" SSH connections to each machine with SSH and public keys, it's very easy to run a remote command on the machines. You can use the System.getRuntime().exec() methods to execute a native command from Java. With this you can execute even remote commands on the machine as you would do on the command line with an SSH client on the machine running your JSF application.

For feedback from the log files the simplest approach from the perspective of your application would be to configure the syslog service of the remote machines to do additional logging to a central syslog server on your central machine. Then you would have direct I/O access from your JSF application. The other way would be with remote commands like above.

A completely different approach would be to use RMI. For this you would of course have to write a client and a server part. And you would have to run a small Java application to communicate with on each of the remote machines.

Possibly there are some other scenarios how to do this but I think a pure Java solution with RMI or a solution with SSH would be the most common approaches.

Marco
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Thanks Marco for your response.
Basically I am doing through SSH but in order to automate I am looking for a possibility of doing a web front end so that I can access a linux server to run some command line options using user's input. Is there any small example to start with?
Regards
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1282

Basically the steps are as follows:

You should establish successful public key authentication so that you don't have to use username/password authentication. For this to work you'll have to create a private/public key pair on the central host where you're going to run your JSF management application. Here is a small to tutorial. You don't have to use the ssh agent. It's sufficient to create the said key pair on the central host and copy the public key to all remote hosts you want to control. On most modern Linux systems you won't even have to configure the ssh daemons on the remote hosts to allow public key authentication, so this is no big deal.

If you're done with this step you can easily test it on the console of the central host. You can execute an arbitrary command on a remote host by typing "ssh this.is.your.remote.host your_command" on the command line, for example "ssh host1.yourdomain.com ls -l" will execute the Linux command "ls -l" on host "host1.yourdomain.com". And as I explained above you can use System.getRuntime().exec() to execute an ordinary Linux command from Java code. So I think this step shouldn't be to difficult ;)

To parse your logs on the remote hosts you have different choices as I said. You can use the above method, too, in order to parse the logs with Linux commands and just use the output of the commands you get via the right exec() call.
Or you can configure the remote boxes to directly log to your central host. All popular implementations of the syslog service allow remote logging to a central syslog server. I think this alternative will be easier because you'd only have to do the log file parsing in one place (on your central host) and you can use ordinary Java I/O to access the central log file and parse it with Java's regular expressions or something like this. That's a good tutorial how to set up a central logging host. This may be more work at first but it will be a lot easier to parse the logs and perhaps add additional remote hosts later.

I hope know it's a bit clearer ;)

Marco
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
May be as a beginner, I have no idea where to start. Sorry about that and I will do more intense homework and figure out. Thanks.
Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
Originally posted by Gopu Akraju:
I am supposed to develop a web interface to interact with a linux server and modify one config file and execute certain command lines. I am going to use JF for the front end. There are no database business involved. Main thing would be in running some command lines and checking the log file to proceed to the next command line.

I may also have to access more than one server depending upon the user selection.

host name: XXXX
username : dummy
port no: 22


Can anyone give an outline picture on how to achieve this? Thanks in advance.
Regards



I would suggest getting an java SSH Client Jar, adding this to your project and the rest is easy, the Bean receives instructions from the Web Page, connects to the appropriate Server using the SSH Jar and then you can execute any command you want


http://linuxmafia.com/ssh/java.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: web interface to a linux server