Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run bash file from web page

Tags:

linux

bash

Ok so I have a bash file that does various operations on a linux server.

I need to pass 7-8 variables to the bash file, and these variables will be set by a user on a simple webpage.

Just wondering if this is possible or do I need to script the bash file call through some other language?

Looking into calling functions on a bash file from http://www.tldp.org/LDP/abs/html/functions.html is this the right lines?

can't seem to find a good resource to guide me on this so any links or examples appreciated

like image 899
Fuzzybear Avatar asked Dec 15 '22 08:12

Fuzzybear


1 Answers

If you're running PHP on the web server, then you can post your web form to a PHP script, then use PHP's shell_exec() function to call your bash script and pass the inputs. As paulsm4 mentions above, any time you call a shell script and pass inputs to a shell script from the web, you need to be very careful to sanitize the inputs to prevent injection type of attacks. One way to do this is to do all the validation and sanitization in the PHP script, before calling the shell script by way of shell_exec() to ensure that you are passing only clean input to the shell script.

See http://php.net/manual/en/function.shell-exec.php

like image 131
mti2935 Avatar answered Dec 31 '22 00:12

mti2935