views:

250

answers:

5

I'm trying to create a web application which will get input from system.

What this application should do is to listen what happens when some shell scripts are executing and reporting the status trough web.

An example :

  • I'm copying thousands of records with shell script, and while this is still executing I'd like pass the current status of the script to the web interface. From shell script side I could echo something like "The files are being copied please wait for it to finnish".

Using which programming language from shell side would be the easiest way to pass this to the web interface? I intended to use JSP/JAVA for web.

Is this even the right way to think about this? Every suggestion is welcome

EDIT

Would something like http://nodejs.org/ be useful for this?

A: 

You could put shell script output to some storage on server. And use AJAX on the web page to poll the server and get updates from that storage to the page.

If you will decide to use JSF for web page creation I can recommend "a4j:poll" component from ajax2jsf library. It is very simple and straightforward. Very easy way to poll server from the web page.

Andriy Sholokh
@Andriy Sholokh how would I know if the storage on server is changed and I need to pass another info to the front end, sending ajax requests every few seconds? I want to make this as live as possible
London
@London, yes you can send AJAX requests every few seconds with that frequency you need.
Andriy Sholokh
This will not be reloading the whole page. Only the part of page will be updated continuously by Ajax
Andriy Sholokh
+2  A: 

The Web part of your application can easily read a file or a database, so you just need to make sure that your shell scripts are outputting something for your Java code to update.

For example, if you run your shell script like this

./myscript.sh > mylog.log

Then in your Java code (note that you should not have logic in your JSP), you can read in the file to determine the status of the update, and output the result to your JSP.

It would be better to read the data in from a database, but that would involve you changing your shell script to output the data to a database.

Codemwnci
@Codemwnci I wanted scripts updates to be as live as possible, not sure how will I handle that with log, how would I know if the script has moved on to the next thing, should I read the log file every few seconds?
London
That would be the way I would go about it. If you want the script to push data to the web page, then you could have a Java program running on your server that checked for updates to the log files, and then send a request to your web application (Web service request, socket request or even update a database and let your server poll the database at regular intervals) informing it of the changes
Codemwnci
@Codemwnci Point taken +1 for now, thank you for your answer I'll see what others are saying a bit longer.
London
+6  A: 

I'd use a named pipe (FIFO) instead. You simply write your output to the pipe and let the application read it. I'm not sure if there is any other way to get a more live system than this.

I'd recommend Perl as the back-end.

EDIT:

named pipes are a special type of files on UNIX. The abbreviation FIFO stands for "First In First Out". On LINUX Journal you can find an interesting read about named pipes.

Perl is a very powerful scripting language with many ready-to-use modules which you can find on http://cpan.org. You can find some answers here on SO about how/where to start learning Perl.

Octavian Damiean
@Octavian Damiean I have no expirience with the perl, I am willing to learn, can you clarify a bit your answer. Maybe provide some links
London
@London: Edited my answer with more information.
Octavian Damiean
A: 

Writing to log file would be the simplest solution. And in programming, simple often means good.

If you really need very fast/realtime system, you should probably make these logs a database.

As for language, use what you like best. They all do support SQLite, including bash.

kolobos
A: 

If I understand your question correctly you want to display a web page on a client machine that reports the status of a long running task on a server machine. If that is the case then you need to focus on something called AJAX IMO.

For what it is worth the simplest and easiest to understand implementation of AJAX that I know of is Apache Wicket.

BigMac66