Executing bash script from web

DrJohnZoidberg

Honorary Master
Joined
Jul 24, 2006
Messages
28,001
Reaction score
7,461
Location
Table View
Hi guys,

I need to create a php page that allows users to execute a custom bash script on the server it's running on. How would I go about doing this and how can I get the output of the script to be displayed on the webpage?

If you could point me in the right direction it would be appreciated.
 
This is more or less what I used to get a list of IP addresses for the machine I'm running on:

PHP:
exec("/sbin/ifconfig", $netinfo);
$netregex='/inet addr:(\d+\.\d+\.\d+\.\d+)/';
print "$netinfo[1] <br><br><br>";
preg_match($netregex, $netinfo[1], $matches);
 $ips=$matches[1];
 
Its a bad idea to execute scripts directly from a web application, drop it in rabbitmq, validate the script and then execute, save the results to a database table and display.

Or drop it in rabbitmq, create a web socket and execute the script via node, push results to the client.
 
I don't quite see the point of the rabbitmq step, just trying to sound clever?

There is no difference in having a consumer subscribed to a queue call a service/manager to validate and execute, compared to your controller calling said service.
 
Thanks for the input all!

I really don't need it to be complicated, it's just for a local intranet site in the office that about 4 people are going to be using. All validation takes place in the script itself, that thing is rock solid and will not run if the conditions are not exactly right.
 
So you just want to run an existing script that is already on the server? Php's exec sounds perfect
 
Its a bad idea to execute scripts directly from a web application, drop it in rabbitmq, validate the script and then execute, save the results to a database table and display.

Or drop it in rabbitmq, create a web socket and execute the script via node, push results to the client.

Rofl my god there are such better ways to do than using a message bus. Like _kabal_ said you're just trying to sound clever.
 
Rofl my god there are such better ways to do than using a message bus. Like _kabal_ said you're just trying to sound clever.

Care to enlighten us? But, let's make the problem a bit more interesting and say the site is going to be hammered day and night by hundreds of concurrent users.
 
Care to enlighten us? But, let's make the problem a bit more interesting and say the site is going to be hammered day and night by hundreds of concurrent users.

The script is the least of your problems correctly setup server, http load balanced, software serving the pages etc.
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X