Jump to content

Calling shell scripts and waiting for output


Grandioso

Recommended Posts

Hey guys.

 

I'll be doing a frontend for some router testing scripts and I'll need to launch some shell scripts in php. The user will be allowed to check some checkboxes - choose which tests to run and run them using a button. I want to show them some kind of "Testing in progress" string and then show them the result when it's done. What do you think is the best solution ?

 

I was thinking the shell script should create the whole output in some sensible form and then I would just parse it. Should I use a database for storing the error strings, or do you think they should be a part of the script ?

 

Also, I would like to do it with AJAX (I never did it before and I could use some experience). So I need some advice on this. I want the form to disappear after the button was pressed, replace it with the "testing in progress" string (or maybe a temporary popup window would be better) and then if the script is done, display the result. I guess I need to use the

shell_exec

command.

What would you suggest ?

 

btw I guess there is no way to run a script on a different server than one which runs the webpage, is there ?

Link to comment
Share on other sites

There is no simple way to run a script on a different server.  If you want maximum reliability then you can create a db table which stores the command, who triggered it and when, which server it's running on, its output (or the name of a file containing the full output), any errors, and anything else interesting.

 

The front end adds an entry to that table, and the AJAX calls a simple script that checks if the db table entry is marked as "done".  In the meantime, another job, which can run on another server, polls that db table and starts anything that needs starting.

 

The most complex script is the one that runs each job, monitors it and makes sure any error status is recorded.  The job may crash altogether, in which case the monitor needs to detect that and record it in that db table.  If the script succeeds then the job itself can update the db table.

Link to comment
Share on other sites

The scripts will only run on one server, I was just asking out of curiosity.

Thanks for the help.

 

I think I'll need to check some AJAX tutorials, because I have no idea where to start.

Currently I was thinking about doing it like this:

 

The form will be handled by another script, which will display the names of all tests and put a thick next to the ones that have succeeded.

The test will be assigned some ID and a row in the database. The script will update the database record after each test. The page will check this database every second and update the content.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.