Run the bash file from the web page

So, I have a bash file that performs various operations on a linux server.

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

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

Including call functions in a bash file from http://www.tldp.org/LDP/abs/html/functions.html are the correct lines?

doesn't seem to be able to find a good resource that will help me with this, so any links or examples appreciated

+4
linux bash
source share
2 answers

If you use PHP on a web server, you can publish your web form to a PHP script, and then use the PHP shell_exec() function to call your bash script and pass the inputs. As paulsm4 mentions above, every time you invoke a script shell and transfer inputs to a script shell from the Internet, you have to be very careful to sanitize the inputs in order to prevent injection attacks. One way to do this is to do all the validation and sanitation in a PHP script before calling the shell script using shell_exec () to make sure that you only pass pure input to the shell script.

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

+7
source share

Yes, you can. You want a "CGI" (Common Gateway Interface). This is a huge potential security risk: be careful!

Just google for cgi bash. For example:

+2
source share

All Articles